当我们传入的单个参数为java.lang.Integer或java.lang.String时,如果我们不进行动态SQL拼接,是不会报错的,当进行动态拼接时,则会报错,错误如下
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'rname' in 'class java.lang.String'
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'rname' in 'class java.lang.String'
1.接口代码
intselectCount(String rname);
2.配置文件代码
<select id="selectCount" resultType="int" parameterType="string">
select count(*) from cst_customer where 1=1<if test="rname!=null and rname!=''">
and cust_name like #{rname}</if></select>
3.如何解决
<select id="selectCount" resultType="int" parameterType="string">
select count(*) from cst_customer where 1=1<if test="_parameter!=null and _parameter!=''">
and cust_name like #{rname}</if></select>