报错案例:
接口:
void updateUserInfo(int money, String user_id);
映射文件:
<update >
update t_user set points = points + #{money} where user_id = #{user_id}
</update>
原因:根据提示,发现它说它没有识别我传入的两个参数,平时,也没有在意,传入的基本上是一个对象或者map之类的内容。所以导致报错。
解决方案:
方案1:
修改映射文件为:
<update >
update t_user set points = points + #{arg0} where user_id = #{arg1}
</update>
修改money为arg0,修改user_id为arg1
方案2(推荐):
修改接口:
void updateUserInfo(@Param("money") int money, @Param("user_id") String user_id);
@Param绑定参数
补充:如果传入多个对象,也可以使用@Param进行绑定,对象中的属性,通过xxx.属性名,进行注入。