1.在Oracle数据库中,字段类型为DATE,在实体类中,对应的属性类型为String,
2.在MyBatis查询数据库的SQL语句为:
<!-- 根据指定条件获取档案 -->
<select id="getArchivesByMap" resultMap="BaseResultMap" parameterType="Map" >
SELECT * FROM archives
WHERE 1 = 1
<if test="createdBy != null and createdBy !=''">
AND CREATED_BY = #{createdBy}
</if>
<if test="duns != null and duns !=''">
AND DUNS = #{duns}
</if>
<if test="archiveid != null and archiveid !=''">
and ARCHIVEID =#{archiveid}
</if>
<if test="fullname != null and fullname!= ''">
and FULLNAME LIKE CONCAT(CONCAT('%', #{fullname}),'%')
</if>
<if test="updatedDate != null and updatedDate != ''">
and UPDATED_DATE >to_date(#{updatedDate},'yyyy-mm-dd hh24:mi:ss')
</if>
order by UPDATED_DATE DESC
</select>
该SQL语句涉及到多条件动态组合,模糊查询,查询指定日期之后的数据(常用于数据更新),注意加上to_date函数,#{updatedDate}不需要加上引号,后面把文本转为什么格式的时间要加上,用引号引起来。
在控制器中,添加上updatedDate作为条件即可,
Map<String, Object> map = new HashMap<String, Object>();
String updatedDate = request.getParameter("updatedDate");
map.put("updatedDate", updatedDate);
List<Archive>ytj2001s =archivesService.getArchivesByMap(map);