nvalid comparison: java.util.Date and java.lang.String
开发中改动mapper文件后需要重新编译发布, 由于工程比较大非常耗时, 所以为方便快速测试干脆写了一个小java工程. 工程中用到的dao, mapper和实体类都是从工程中拷出来的, 数据库也是同一个. 但是遇到一个比较奇怪的问题
实体类中有一个属性
private Date createTime;
对应该属性数据库中定义的是
create_time datetime
mapper中该属性映射的定义
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
以下是mapper中对应Dao方法SQL语句
<select id="selectByCreateTime" resultMap="userMap">
select * from user
<where>
<if test="createTime != null and createTime !='' " >
date(create_time) = date(#{createTime,jdbcType=TIMESTAMP})
</if>
</where>
</select>
其中date()函数只是用来把年月日时分秒的日期截取为年月日, 这个对于该异常没有任何影响
在测试类中创建实体并为其属性赋值
User user=new User();
user.setCreateTime(new SimpleDateFormat("yyy