我的sql版本是5.6.16.5和 我的java代码是:
Calendar theCa = Calendar.getInstance();
theCa.setTime(new Date());
theCa.set(Calendar.HOUR_OF_DAY, 0);
theCa.set(Calendar.MINUTE, 0);
theCa.set(Calendar.SECOND, 0);
Date date = theCa.getTime();
StationActivityQuery query = new StationActivityQuery();
query.setRegisterStart(date);
List<StationActivityDO> activities = stationActivityDAO.queryActivityList(query);
我查询一些Activity对象使用条件RegisterStartDate,RegisterStartDate的类型是java.util.Date.Andadbase类型的RegisterStartDate是date而不是datetime.I发现我找不到任何结果使用这段代码:
<select id="StationActivityDAOImpl.select" parameterClass="StationActivityQuery" resultMap="StationActivityDO_ResultMap">
select * from sta_activity where is_deleted = 0
<dynamic prepend="and">
<isNotNull property="registerStart" prepend="and">
register_start=#registerStart#
</isNotNull>
</select>
但我可以找到结果使用代码:
<select id="StationActivityDAOImpl.select" parameterClass="StationActivityQuery" resultMap="StationActivityDO_ResultMap">
select * from sta_activity where is_deleted = 0
<dynamic prepend="and">
<isNotNull property="registerStart" prepend="and">
register_start=date(#registerStart#)
</isNotNull>
</select>
然后我用sql来查询:
SELECT * from sta_activity where register_start='2015-09-24 00:00:00'
我可以查询一些结果。 然后我用sql来查询:
SELECT * from sta_activity where register_start='2015-09-24'
我也可以获得与使用register_start='2015-09-24 00:00:00'
时相同的结果,所以当我没有将date()
功能添加到
<isNotNull property="registerStart" prepend="and">register_start=date(#registerStart#)</isNotNull>