Mybatis single parameter pass in exception (How to Fix)

MyBatis passes in an exception for a single parameter

Integer or java.lang.String, if we do not perform dynamic SQL splicing, it will not report an error, when performing dynamic splicing, it will report an error, the error is as follows

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. Interface code

 int selectCount(String rname);

2. Configuration file code

  <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. How to solve it

   <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>

4. Why are errors reported

When passing a single parameter to dynamically splice sql, mybatis converts our parameter to _parameter by default, or you can add the @Param comment to the interface field.

Read More: