maven工程过程中常见的错误2(初学者笔记)

1.数据库时区的设置,由于数据库和数据连接工具版本不同,需要设置时区,如图:

//未设置时区报错
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project empsys3: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

//设置时区
//db.properties设置

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/emps?serverTimezone=GMT&useSSL=false&characterEncoding=utf-8

//mybatis-config.xml中设置
<!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/emps?serverTimezone=GMT&amp;useSSL=false&amp;characterEncoding=utf-8"
                        userId="root" password="YCF500095">
        </jdbcConnection>

2.EL表达式书写错误,漏写了$,所以提交的值得类型变成了String型,而且没有具体值。所以报错:

HTTP Status 400 - 

type Status report
message 
description The request sent by the client was syntactically incorrect.

Apache Tomcat/7.0.47

错误原因:
Method [public java.lang.String com.study.controller.EmployeeController.detailEmployee(java.lang.Integer,org.springframework.ui.Model)]

  org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.lang.Integer]; nested exception is java.lang.NumberFormatException: For input string: "{empVo"
	at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:115)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)

错误处:
<td><a href="${pageContext.request.contextPath}/detailEmp/{empVo.empid}">详细</a></td>
                    <td><a href="javascript:del(${empVo.empid})">删除</a></td>
                    <td><a href="${pageContext.request.contextPath}/pre_update/{empVo.empid}">修改</a></td>

把详细和修改的{empVo.empid}改成${empVol.empid}即可

引起此类错误还有可能数据类型不匹配:比如时间,需要在实体类中加上注解@DateTimeFormat(pattern="")

3.提交方式和注解不匹配,改为post,如果不可以,注解匹配两个提交方式:@RequestMapping(....,method={RequestMethod.POST,RequestMethod.GET}

HTTP Status 405 - Request method 'GET' not supported

type Status report
message Request method 'GET' not supported
description The specified HTTP method is not allowed for the requested resource.

Apache Tomcat/7.0.47

4.数据提交方式不同,参数匹配也不同,如下对应:

//前端提交方式
<td><a href="${pageContext.request.contextPath}/detailEmp/${empVo.empid}">详细</a></td>
//后端注解
  @RequestMapping(value = "/detailEmp/{empid}",method = RequestMethod.GET)
  public String detailEmployee(@PathVariable(value = "empid")Integer empid,Model model){......}


//前端提交方式
<td><a href="${pageContext.request.contextPath}/detailEmp?empid=${empVo.empid}">删除</a></td>

//后端注解
    @RequestMapping(value = "/deleteEmp",method = RequestMethod.GET,produces = "text/html;charset=utf-8")
    @ResponseBody
    public String deleteEmployee(@RequestParam(value = "empid")Integer empid){......}

5.有时候日期显示不出来,可能是有多余的空格,如下

//在</fmt:formatDate>之后多了一个空格,结果日期就是无法显示出来
<td><input type="date" name="hiredate" id="hiredate" value='<fmt:formatDate value="${requestScope.employeeVo.hiredate}" pattern="yyyy-MM-dd"></fmt:formatDate> '/></td>

6.第六次练习打包出错:原因是我的配置文件的数据库名没有改(细心很重要)

//没改之前
jdbc.url=jdbc:mysql://localhost:3306/demo?serverTimezone=GMT&useSSL=false&characterEncoding=utf-8

//改了之后
jdbc.url=jdbc:mysql://localhost:3306/emps?serverTimezone=GMT&useSSL=false&characterEncoding=utf-8
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project empsys6: Unknown database 'demo' -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1

猜你喜欢

转载自blog.csdn.net/preston555/article/details/110871240