mybatis 参数为list时,校验list是否为空, mybatis ${}与#{}的区别,Mybatis sql in

时间:2023-03-09 17:40:34
mybatis 参数为list时,校验list是否为空, mybatis ${}与#{}的区别,Mybatis sql in

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

mybatis 参数为list时,校验list是否为空, mybatis ${}与#{}的区别,Mybatis sql in

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

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

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