我使用的是mybatis 3.2.8版本。
映射器.java
List<BuddyId> findBuddyIds(HashMap<String, Object> map);
xml
<select id="findBuddyIds" parameterType="map" resultMap="BuddyIdResultMap">
select *
from seerid.buddyIds
where id REGEXP
<foreach collection="idSplits" item="item" index="index" open="'" close="'" separator="|">
#{item}
</foreach>
</select>
控制器.java
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("idSplits", new ArrayList<String>(Arrays.asList(idSplits)));
buddyScanResult = seerIdDAO.findBuddyIds(map);
它将收到以下错误。
查询数据库时出错。原因:java.sql.SQLException:无法设置参数
该错误可能存在于文件[/Users/jylee/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/services/WEB-INF/classes/com/ohinc/services/ seerid/mybatis/SeerIdMapper.xml]
错误可能涉及 com.ohinc.services.seerid.mybatis.SeerIdMapper.findBuddyIds-Inline
设置参数时出现错误
SQL: select * from seerid.buddyIds where id REGEXP ' ? | ? '
原因:java.sql.SQLException:无法设置参数; SQL[] 的未分类 SQLException; SQL状态[空];错误代码
[0];无法设置参数;嵌套异常是
java.sql.SQLException:无法设置参数],根本原因
org.mariadb.jdbc.internal.common.query.IllegalParameterException:否
'?'在那个位置
org.mariadb.jdbc.internal.common.query.MySQLParameterizedQuery.setParameter(MySQLParameterizedQuery.java:103)
我不知道如何解决这个问题。
请帮我。
我发现了这个问题,也许可以解决这个问题。
你的xml有一个错误:
<select id="findBuddyIds" parameterType="map" resultMap="BuddyIdResultMap">
select *
from seerid.buddyIds
where id REGEXP
<foreach collection="idSplits" item="item" index="index" open="'" close="'" separator="|">
${item}
</foreach>
</select>
你应该在 foreach 中使用 $ 替换 # 。
MyBatis 的 IN 条件问题 https://stackoverflow.com/questions/21374677/mybatis-issue-with-in-condition-foreach-with-list-inside-a-map
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)