ibatis 查询条件中存在逗号,怎么办。
<updateid="updateSentence"parameterClass="String">updateSentencesetisRead=1whereisRea...
<update id="updateSentence" parameterClass="String">
update Sentence
set isRead = 1
where isRead = 0 and
id in (#sentence# )
</update>
这事我的sqlmap中的sql语句 希望传递的参数是 ‘1’,‘2’,‘3’
最后我想达到的sql语句是
update Sentence
set isRead = 1
where isRead = 0 and
id in (‘1’,‘2’,‘3’)
我传入字符串是‘1’,‘2’,‘3'
但是不好使,所以我进行一系列尝试,首先传入字符串’1‘
还是不好使,我在尝试传入字符串 1
传入字符串1的时候,能够进行修改,ibatis自动添加了单引号(估计是后台jdbc自动添加的引号),
后来在控制台打印了sql语句还有一系列语句发现
[2013-09-03 05:33:55,051] [DEBUG] java.sql.Connection
--{conn-100003} Preparing Statement: update Sentence set isRead = 1 where isRead = 0 and id in (? ) --
[2013-09-03 05:33:55,051] [DEBUG] java.sql.PreparedStatement
--{pstm-100004} Executing Statement: update Sentence set isRead = 1 where isRead = 0 and id in (? ) --
[2013-09-03 05:33:55,051] [DEBUG] java.sql.PreparedStatement
--{pstm-100004} Parameters: [03-1309030333-77330002','001','03-1309030334-61700001','003','002','004]--
[2013-09-03 05:33:55,051] [DEBUG] java.sql.PreparedStatement
--{pstm-100004} Types: [java.lang.String]--
[2013-09-03 05:33:55,083] [DEBUG] com.ibatis.common.jdbc.SimpleDataSource
--Returned connection 16695559 to pool.--
我怀疑是不是ibatis把我传递的字符串当做多个参数了,希望找到解决方案 展开
update Sentence
set isRead = 1
where isRead = 0 and
id in (#sentence# )
</update>
这事我的sqlmap中的sql语句 希望传递的参数是 ‘1’,‘2’,‘3’
最后我想达到的sql语句是
update Sentence
set isRead = 1
where isRead = 0 and
id in (‘1’,‘2’,‘3’)
我传入字符串是‘1’,‘2’,‘3'
但是不好使,所以我进行一系列尝试,首先传入字符串’1‘
还是不好使,我在尝试传入字符串 1
传入字符串1的时候,能够进行修改,ibatis自动添加了单引号(估计是后台jdbc自动添加的引号),
后来在控制台打印了sql语句还有一系列语句发现
[2013-09-03 05:33:55,051] [DEBUG] java.sql.Connection
--{conn-100003} Preparing Statement: update Sentence set isRead = 1 where isRead = 0 and id in (? ) --
[2013-09-03 05:33:55,051] [DEBUG] java.sql.PreparedStatement
--{pstm-100004} Executing Statement: update Sentence set isRead = 1 where isRead = 0 and id in (? ) --
[2013-09-03 05:33:55,051] [DEBUG] java.sql.PreparedStatement
--{pstm-100004} Parameters: [03-1309030333-77330002','001','03-1309030334-61700001','003','002','004]--
[2013-09-03 05:33:55,051] [DEBUG] java.sql.PreparedStatement
--{pstm-100004} Types: [java.lang.String]--
[2013-09-03 05:33:55,083] [DEBUG] com.ibatis.common.jdbc.SimpleDataSource
--Returned connection 16695559 to pool.--
我怀疑是不是ibatis把我传递的字符串当做多个参数了,希望找到解决方案 展开
1个回答
推荐于2016-03-14
展开全部
传入list
然后修改SQL。
例如
<select id="selectProduct" resultMap="Map">
SELECT *
FROM Sentence
WHERE SentenceNo IN
<foreach item="SentenceNo" index="index" collection="参数的类型List或array">
#{SentenceNo}
</foreach>
</select>
然后修改SQL。
例如
<select id="selectProduct" resultMap="Map">
SELECT *
FROM Sentence
WHERE SentenceNo IN
<foreach item="SentenceNo" index="index" collection="参数的类型List或array">
#{SentenceNo}
</foreach>
</select>
追问
xml提示在中不允许使用标签
追答
myBatis中,是可以的,不行你就升级吧。
update Sentence set state = '0' where no in
#{nos}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询