mybatis 映射文件:
<select id="queryFuzzyMessagesByUser" parameterType="Map" resultType="MessageDto">
select
<include refid="messageInfo" /> , <include refid="uInfo" />
from tb_message m , tb_user u
<where>
m.user_id = u.id and m.f_type = 0
<if test="messageId != null and messageId != ''">
and m.id = #{messageId,jdbcType=NUMERIC}
</if>
<if test="title != null and title != ''">
and m.title like '%${title}%'
</if>
<if test="userId != null and userId != ''">
and u.id = #{userId,jdbcType=NUMERIC}
</if>
<if test="sDateMin != null">
and m.s_date >= #{sDateMin, jdbcType=DATE}
</if>
<if test="sDateMax != null">
and m.s_date <= #{sDateMax, jdbcType=DATE}
</if>
<if test="sTimeMin != null">
and m.s_time >= #{sTimeMin, jdbcType=TIME}
</if>
<if test="sTimeMax != null">
and m.s_time <= #{sTimeMax, jdbcType=TIME}
</if>
</where>
</select>
service 层代码:
Map<String,Object> param = new HashMap<String,Object>();
Calendar c = Calendar.getInstance();
c.set(2013, 1, 18, 1, 30);
param.put("sDateMin", new Date(c.getTimeInMillis()));
Time a = new Time(c.getTimeInMillis());
param.put("sTimeMin", a.toString());
c.set(2015, 8, 18, 14, 50);
param.put("sDateMax", new Date(c.getTimeInMillis()));
a = new Time(c.getTimeInMillis());
param.put("sTimeMax",a.toString());
List<MessageDto> ms = _mService.queryFuzzyMessagesByUser(param);
for(MessageDto m : ms){
System.out.println(m.getId());
}
今天不知道为什么,总是不在状态!尤其是出现了这种狗屎问题,今天贴出来,以免以后踩到狗屎......................
在 java service 层:使用HashMap传值,结果传入了NULL到数据库,映射名称完全没有问题,后来发现了:原来是我在映射文件那里多了空格!面壁........
<if test="sDateMin != null">
and m.s_date >= #{sDateMin , jdbcType=DATE}
</if>