在写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注解

 
  1. public AreaDict selectById(@Param("id") Integer id);

  2.  
  3. select * from area_dict where area_dict_id = ${id}

2、将${}换成#{}取值,#{}能防止sql注入,${}只是简单的字符串替换,#{}先进行预处理

select * from area_dict where area_dict_id = #{id}

3、通过${value}或${_parameter}取值

 
  1. select * from area_dict where area_dict_id = ${_parameter}

  2. select * from area_dict where area_dict_id = ${value}

参考地址  https://blog.csdn.net/qq_30604989/article/details/81297400

https://blog.csdn.net/wrongyao/article/details/83501334

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐