mybatis往配置文件中传入拼接好的条件语句 30
在程序中生成了字符串“(age>'20'and'200'>ageandsex='1')”,现在要传入到配置文件中,大于号换成>单引号换成'都试过了,配置文件里面...
在程序中生成了字符串 “( age >'20' and '200'>age and sex='1' ) ”,现在要传入到配置文件中,大于号换成>单引号换成'都试过了,配置文件里面是这么写的
<select id="queryByCondition" parameterType="java.util.HashMap"
resultMap="BaseResultModelMap">
select * from user where 1=1
<if test="Condition!=null">
#{Condition,jdbcType=VARCHAR}
</if>
<if test="start!=null">
limit #{start,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER}
</if>
</select>
Condition就是我传入的字符串,现在总是报错,错误信息是
DEBUG - ==> Executing: select * from user where 1=1 ?
DEBUG - ==> Parameters: and ( age >'20' and '200'>age and sex='1' ) (String)
org.apache.ibatis.exceptions.IbatisException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''and ( age >\'20\' and \'200\'>age and sex=\'1\' ) '' at line 3
### The error may involve com.goalwisdom.gwnis.repository.dao.UserDao.queryByCondition-Inline
### The error occurred while setting parameters
提问中的大于号& g t;直接被网页转义了,分号也是,
最好是谁有写过这样的代码把字符串的格式和XML文件中接收方式粘贴上来 展开
<select id="queryByCondition" parameterType="java.util.HashMap"
resultMap="BaseResultModelMap">
select * from user where 1=1
<if test="Condition!=null">
#{Condition,jdbcType=VARCHAR}
</if>
<if test="start!=null">
limit #{start,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER}
</if>
</select>
Condition就是我传入的字符串,现在总是报错,错误信息是
DEBUG - ==> Executing: select * from user where 1=1 ?
DEBUG - ==> Parameters: and ( age >'20' and '200'>age and sex='1' ) (String)
org.apache.ibatis.exceptions.IbatisException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''and ( age >\'20\' and \'200\'>age and sex=\'1\' ) '' at line 3
### The error may involve com.goalwisdom.gwnis.repository.dao.UserDao.queryByCondition-Inline
### The error occurred while setting parameters
提问中的大于号& g t;直接被网页转义了,分号也是,
最好是谁有写过这样的代码把字符串的格式和XML文件中接收方式粘贴上来 展开
2个回答
2014-08-25
展开全部
用转义符:demo如下
<![CDATA[
when min(starttime)<='12:00' and max(endtime)<='12:00'
]]>
追问
不行,这个我试过了的,接收字符串的方式应该存在问题,网上能查的基本都查过了,需要有写过的人的完整代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询