MyBatis “#”号和“$” 区别 遇到的坑 -- softwbc 发布于:2018年06月20日 浏览量:1687  |

最近在项目中需要批量传部门ID参数做查询
接口一:
public Page<Document> selectByCondition(@Param("paramMap") Map<String, Object> paramMap, Pageable pageable);

mapper中sql
.... inner join (SELECT xxxxx FROM 表 as VR WHERE 

<if test="paramMap.dept != null">

    AND VR.ownDept in

   <foreach collection="paramMap.deptList" item="it" open="(" separator="," close=")">'${it}'</foreach>

</if>

...)....

此段代码,必须用'${it}' 要是用#{it}会报:

1
2
Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_it_0' not found. Available parameters are [1, paramMap, param1, param2]
Caused by: org.apache.ibatis.binding.BindingException: Parameter '__frch_it_0' not found. Available parameters are [1, paramMap, param1, param2]

接口二:
int selectCountByCondition(Map<String, Object> paramMap);

.... inner join (SELECT xxxxx FROM 表 as VR WHERE 

<if test="dept != null">

 AND VR.ownDept in

 <foreach collection="deptList" item="it" open="(" separator="," close=")">'${it}'</foreach>

 </if>
...)....

用#{it} 和 '${it}'都可以

评论|回复
暂无评论

关于我们 |  广告服务 |  联系我们 |  网站声明

Copyright © 2015 - 2016 DISPACE.NET |  使用帮助 |  关于我们 |  投诉建议

京ICP备13033209号-2