一、错误展示
Error updating database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
### Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 117 common frames omitted
在前台数据创建插入到后台的过程中,一直提示说后台的插入日期格式不正确,检查发现是因为数据库中的字段创建的时候设置成了varchar类型。
如图:创建字段的时候声明成了varchar类型
然后我就很自信的改成了datetime类型。以为就此久万事大吉了,可是生活却给我沉重一击,此路不通。灵光一闪,难道是我的赋值的错误了吗?
于是,就检查了下面的代码,并没有任何破绽。
public int insertCourseSelectRounds(SelectRounds selectRounds)
{
selectRounds.setCreateTime(DateUtils.getNowDate());
selectRounds.setCreateUser(String.valueOf(ShiroUtils.getUserId()));
return selectRoundsMapper.insertselectRounds(selectRounds);
}
于是只能取检查mapper文件,果不其然,在mapper文件中有一处判断。
<if test="createTime != null and createTime = '' ">#{createTime},</if>
没错就是这句 and createTime = ‘’ 除了问题,Date类型是不能和空字符串相比较的,所以将这个删掉,Ok,插入成功!(主要是使用mybatis的逆向工程生成的锅,害的我找半天)