There is no getter for property named '*' in 'class java.lang.String' 此错误之所以出现,是因为mybatis在对parameterType="String"的sql语句做了限制,假如你使用
XXXMapper.java【接口】
ProjectInfo selectByExample(String projectNum);
XXXMapper.xml
- <select id="selectByExample" resultMap="BaseResultMap" parameterType="String">
- select * from project_info where
- 1=1
- <if test="projectNum != null and projectNum !=''">
- and project_num = #{projectNum}
- if>
- select>
1parameterType="String",这一点是必须得,参数类型必须是string。
2该sql对应的XXXMapper.java中对应的方法为ProjectInfo selectByExample(String projectNum);,也就是说,传递的参数名为projectNum,正常情况下,这样的配置合情合理。
3,你有一个对应的test判断语句,也可能是when。
4那么这个时候,项目运行该查询语句时,就会抛出There is no getter for property named 'projectNum ' in 'class java.lang.String'错误!
直接在XXXMapper.java的接口中参数中加上@Param("projectNum"),其他地方不用进行改变。
ProjectInfo selectByExample(@Param("projectNum") String projectNum);
然后重新启动进行测试。
解决办法很简单,你只需要把
- <select id="selectByExample" resultMap="BaseResultMap" parameterType="String">
- select * from project_info where
- 1=1
- <if test="projectNum != null and projectNum !=''">
- and project_num = #{projectNum}
- if>
- select>
然后重新启动进行测试。
源码分析:源码分析 There is no getter for property named '*' in 'class java.lang.String_沉默王二的博客-CSDN博客