9AMC 发表于 2016-11-24 08:39:55

mybatis注意事项

---------------------以数组作为查询条件,判断数组大小
<if test="dateList != null and dateList.size() > 0">
        and DATE_FORMAT(tfp.update_time, '%Y-%m-%d') in
        <foreach item="date" index="index" collection="dateList" open="(" separator="," close=")">  
 #{date}  
</foreach> 
</if> 
 
------------------------mybatis字符串比较方法
<if test='deviceStatus != null and deviceStatus != "" and deviceStatus == "0" '>
and (vdm.`status` is null or vdm.`status` = '')
</if>
 
注意单引号和双引号的用法
<if test='deviceStatus != null and deviceStatus != "" and deviceStatus == "0" '>
and (vdm.`status` is null or vdm.`status` = '')
</if>
 
注意单引号和双引号的用法
 
-------------------------------参数数组判断空
  <if test="deviceIds != null and deviceIds.size() > 0">
  and t.DEVICE_ID in
  <foreach item="deviceId" index="index" collection="deviceIds"
  open="(" separator="," close=")">
  #{deviceId}
  </foreach>
  </if>
  mybatis存储过程类型定义如下:
  http://blog.csdn.net/woshixuye/article/details/12953803
  ===Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for integralSQL.hashmap
  原因:  <select id="selectProductExchangeOrder" resultMap="hashmap" parameterType="hashmap" >
  应该为  <select id="selectProductExchangeOrder" resultType="hashmap" parameterType="hashmap" >
   
  resultMap 改为 resultType
  注意:mybatis执行sql检测整个mapper文件的语法,不要只关注你执行的那句sql是不是有语法错误,要看这个mapper文件是不是有语法错误
   
页: [1]
查看完整版本: mybatis注意事项