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>