Parameter 'num' not found. Available parameters are [1, product_id, param1, param2]

一. 问题背景

后台:使用SSM框架
前端:出现org.apache.ibatis.binding.BindingException: Parameter ‘num’ not found. Available parameters are [1, product_id, param1, param2]报错

原因: 这是因为mybatis将参数传入sql语句中的时候,由于匹配不到是要传入哪个变量,所以报错。

二. 解决方案

  • xxxMapper.java 的方法中,在其参数前加上@Param("xxx") 即可。如下:
public Integer updateSalesAndStock(@Param("product_id")Integer product_id,
 @Param("num")Integer num);
  • 这样就可以直接在=xxxMapper.xml 的sql语句中直接取值
<!-- public Integer updateSalesAndStock(Integer product_id, Integer num); -->
	<update id="updateSalesAndStock">
	   update up_product set
	   sales = sales + #{num},
	   stock = stock - #{num}
	   where product_id = #{product_id}
	</update> 
发布了345 篇原创文章 · 获赞 20 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_40634846/article/details/105138686