首页 > 技术文章 > mybatis 参数为list时,校验list是否为空, mybatis ${}与#{}的区别,Mybatis sql in

guoziyi 2016-11-22 11:14 原文

1、mybatis 参数为list时,校验list是否为空

 

2、 mybatis ${}与#{}的区别

简单来说#{} 解析的是占位符?可以防止SQL注入, 比如打印出来的语句 select * from table where id=?
然而${} 则是不能防止SQL注入打印出来的语句 select * from table where id=2  实实在在的参数。
最简单的区别就是${}解析穿过来的参数值不带单引号,#{}解析传过来参数带单引号。
最后总结一下必须使用$引用参数的情况,那就是参数的int型的时候,必须使用$引用。

3、 Mybatis sql in
参数传List
1 <select id="findByIdsMap" resultMap="BaseResultMap">  
2  Select  
3  <include refid="Base_Column_List" />  
4  from jria where ID in  
5  <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
6   #{item}  
7  </foreach>  
8 </select>  

 

 

推荐阅读