mybatis0010-There is no getter for property named 'id' in 'class java.lang.Integer'

本文详细介绍了在使用MyBatis框架时遇到的参数传递问题,特别是当mapper方法参数为单一基础类型时,在mapper.xml文件中使用${}

资源贴:https://blog.youkuaiyun.com/qq_33866778/article/details/73199260

当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}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值