会报错:There is no getter for property named 'id' in 'class java.lang.Integer'
这是因为Integer对象中没有id属性
解决办法
select * from Customer where id=#{_parameter}
即将接收参数的参数名改为_parameter,注意改成其他参数名没用。
传入基本类型参数时test判断报错
在使用mybatis的时候出现了这样的问题:
//Dao层的接口中的代码List
//对应的mapper中的代码 select name,client_id from table1 and username= #{id}
//报的错误 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'username' in 'class java.lang.String'
分析
There is no getter for property named ‘username’ in ‘class java.lang.String’,这句话打大概意思是:在"class java.lang.String"中没有名为"username"的属性的getter方法。因为mybatis默认采用ONGL解析参数,所以会自动采用对象树的形式取string.num值,引起错误。
解决办法
if test中的id用_parameter替换,而实际的语句不需要修改and a.id =#{id},因为Mybatis当只传入一个参数时#{ } 中的内容没有要求。