@Select({"<script> ",
" SELECT * FROM ext_statement_records WHERE business_system_id=#{businessSystemId} AND <![CDATA[date1 <=#{toDate} ]]> ",
" AND id IN ",
"<foreach collection='idList' item='item' open='(' close=')' separator=',' > ",
"#{item} ",
"</foreach> ",
" </script>"})
List<ExtStatementRecord> batchSelectByPrimaryKeys(@Param("idList") List<Long> idList,
@Param("toDate") Date toDate,
@Param("businessSystemId") Integer businessSystemId);
这里对于 >=, <=比较号,要用 <![CDATA[ ]]> 来包含字段比较,否则会报错,例子如下
<![CDATA[ date1 <= #{toDate} ]]>
该博客讨论了在SQL查询中如何正确处理大于(>)和小于(<)符号,以避免SQL注入问题。示例展示了在Java中使用MyBatis框架时,如何利用CDATA来包裹条件表达式,确保日期比较的安全性。同时,文章提及了批处理查询的方法,涉及到参数绑定和集合处理。
1万+

被折叠的 条评论
为什么被折叠?



