`Exception in thread “main” org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘id’ in ‘class java.lang.Integer’问题解决办法`
(1) 使用xml配置文件的方式
将if块中的判断参数名字改为 “_parameter” ,无论传进来的是什么,一律写为 “_parameter”
example:
<select id="getStudent" parameterType="String" resultType="com.bx.pojo.Student">
select id,name,nickName from Student
<where>
<if test="_parameter != null and '' != _parameter">
id = #{id}
</if>
</where>
</select>
(2)使用注解的方式
①使用<script></script>将select语句包起来,并且在接口类的方法中的参数列表中参数使用@Param(value="id")修饰
example:
@Select("<script> select id,name,nickname from student <where> <if test=\" id!=null and \'\' !=id \"> id = #{id} </if> </where> </script>")
public List<Student> getStudent(@Param(value="id")int id);
②使用 selectProvide接口
example:接口类代码
@SelectProvider(method = "getStudent", type = SqlProvider.class)
public List<Student> getStudent(int id);
SqlProvider类代码:
public String getStudent(Integer id){
String sql = "select id,name,nickName from student";
if(id != null){
sql = sql + " where id = " + id.intValue();
}
return sql;
}