逆向工程生成的文件, 数据库是datetime类型的表 查询,插入 都会出错. mapper是 timestamp类型.po的成员类型 换过sql.date , String也尝试过 , 网上搜了好几个方法都不行.现在的情况 , 不设置该日期字段,可以正常.我重新建了个项目, 依赖是相同的, 但是该为注解方式, 是可以插入日期字段的.
debug信息, 看着也没问题.2018-11-02 10:38:29.829 DEBUG 9884 --- [http-nio-8080-exec-5] com.ctu.dao.MovieMapper.insertSelective : ==> Preparing: insert into movie ( name, classify, district, logo, actor, age, status, update, con ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ? )
2018-11-02 10:38:29.831 DEBUG 9884 --- [http-nio-8080-exec-5] com.ctu.dao.MovieMapper.insertSelective : ==> Parameters: 1231(String), 2(Integer), 431(String), aaa(String), 321(String), 1234(String), 3123(String), 2018-11-02 10:38:29.826(Timestamp), 12356(String)
debug信息, 看着也没问题.2018-11-02 10:38:29.829 DEBUG 9884 --- [http-nio-8080-exec-5] com.ctu.dao.MovieMapper.insertSelective : ==> Preparing: insert into movie ( name, classify, district, logo, actor, age, status, update, con ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ? )
2018-11-02 10:38:29.831 DEBUG 9884 --- [http-nio-8080-exec-5] com.ctu.dao.MovieMapper.insertSelective : ==> Parameters: 1231(String), 2(Integer), 431(String), aaa(String), 321(String), 1234(String), 3123(String), 2018-11-02 10:38:29.826(Timestamp), 12356(String)
2018-11-02 22:15:48.076 DEBUG 10020 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:15:48.079 DEBUG 10020 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:15:48.081 DEBUG 10020 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:15:48.085 DEBUG 10020 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:15:48.091 DEBUG 10020 --- [nio-8080-exec-6] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@1946cdfb
2018-11-02 22:15:48.095 DEBUG 10020 --- [nio-8080-exec-6] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@1946cdfb
2018-11-02 22:15:48.104 DEBUG 10020 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@5d222e24
2018-11-02 22:15:48.105 DEBUG 10020 --- [io-8080-exec-10] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@3e205cf6
2018-11-02 22:15:48.107 DEBUG 10020 --- [io-8080-exec-10] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@3e205cf6
2018-11-02 22:15:48.109 DEBUG 10020 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@5d222e24
2018-11-02 22:15:48.110 DEBUG 10020 --- [nio-8080-exec-1] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@11eb4fe8
2018-11-02 22:15:48.112 DEBUG 10020 --- [nio-8080-exec-1] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@11eb4fe8
2018-11-02 22:15:48.114 DEBUG 10020 --- [nio-8080-exec-9] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:15:48.116 DEBUG 10020 --- [nio-8080-exec-9] o.s.b.w.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:16:24.679 DEBUG 10020 --- [nio-8080-exec-4] o.s.b.w.f.OrderedRequestContextFilter : Bound request context to thread: org.apache.catalina.connector.RequestFacade@4975ee9b
2018-11-02 22:16:24.772 DEBUG 10020 --- [nio-8080-exec-4] com.ctu.dao.MovieMapper.insertSelective : ==> Preparing: insert into movie ( name, classify, district, logo, actor, age, status, update, con ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ? )
2018-11-02 22:16:24.779 DEBUG 10020 --- [nio-8080-exec-4] com.ctu.dao.MovieMapper.insertSelective : ==> Parameters: 名称(String), 1(Integer), 测试地区(String), aaa(String), sdas(String), 3123(String), 1080(String), 2018-11-02 22:16:24.731(Timestamp), 简介(String)
2018-11-02 22:16:24.813 INFO 10020 --- [nio-8080-exec-4] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update,
con )
values ( '名称',
' at line 23
### The error may involve com.ctu.dao.MovieMapper.insertSelective-Inline
### The error occurred while setting parameters
### SQL: insert into movie ( name, classify, district, logo, actor, age, status, update, con ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update,
con )
values ( '名称',
' at line 23
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update,
con )
values ( '名称',
' at line 23
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:230)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy59.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy60.insertSelective(Unknown Source)
at com.ctu.service.impl.MovieImpl.insertSelective(MovieImpl.java:31)
at com.ctu.controller.AddController.saveMovie(AddController.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
idea配置自动生成mybaits实体类和mapper.xml ~ better-mybatis-generator
2.根据精确的后的日期进行插入数据前的格式化
3.若精确后的日期精度过高,建议将数据库表字段改为Timestamp类型,反之只需要再mybatis的xml文件中将该字段的type类型指定为datatime即可