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:
- [Solved] JavaErrors_mybatis collection column Pass Value Error
- [Solved] mybatis plus Insert Error: mybatis plus Error setting null for parameter #1 with JdbcType OTHER
- How to Solve SQL comments error in the mybatis query
- Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…
- Mybatis-plus: How to Execute Native SQL
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- How to Fix COM Surrogate has stopped working in Windows 7
- How to Solve Mybatis error: invalid bound statement (not found)
- How to Fix flink OutputTag Error
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- How to Fix log4j2 warning: warn unable to identify org.fusesource.jansi.WindowsAnsiOutputStream
- Mybatis Error: The error may exist in xxxxMapper.xml [How to Solve]
- Caused by: java.lang.IllegalStateException (How to Fix)
- [Solved] JPA sett in parameter error: Java.lang.illegalargumentexception
- How to Fix “DevTools failed to load SourceMap” Warning
- IDEA-Error java error release version 5 not supported (How To Fix)
- [Solved] Mybatis Error: attempting to get column ‘XX’ from result set
- Mapper.xml Error: Error setting non null for parameter #3 with JdbcType null.