关于 There is no getter for property named 'id' in 'class java.lang.Integer'
Posted roak
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于 There is no getter for property named 'id' in 'class java.lang.Integer'相关的知识,希望对你有一定的参考价值。
在写SSM框架的时候,请求报出 There is no getter for property named ‘id‘ in ‘class java.lang.Integer‘这个问题
但是实际上实体类中写了相关的方法,最后找到问题出现在Mapper接口中,
List<User> getAllUser( Integer id);
将代码改为:
List<User> getAllUser(@Param("id") Integer id);
问题解决
方法2
当mapper的方法参数是基础类型且只有一个时,在mapper.xml文件中使用${}取值时,会报There is no getter for property named ‘id‘ in ‘class java.lang.Integer‘异常。
解决方法
1、@Param注解
public AreaDict selectById(@Param("id") Integer id);
select * from area_dict where area_dict_id = ${id}
2、将${}换成#{}取值,#{}能防止sql注入,${}只是简单的字符串替换,#{}先进行预处理
select * from area_dict where area_dict_id = #{id}
3、通过${value}或${_parameter}取值
select * from area_dict where area_dict_id = ${_parameter}
select * from area_dict where area_dict_id = ${value}
以上是关于关于 There is no getter for property named 'id' in 'class java.lang.Integer'的主要内容,如果未能解决你的问题,请参考以下文章
mybatis There is no getter for property named 'xxxx
实力踩坑:There is no getter for property named ‘XXX‘ ‘class XXX‘
mybatis出现There is no getter for property named ...的原因及解决办法
There is no getter for property named 'NULL' in ……