1. 程式人生 > >Parameter 'stock' not found. Available parameters are [arg1, arg0, param1, param2]

Parameter 'stock' not found. Available parameters are [arg1, arg0, param1, param2]

SpringBoot 2.1.0,mybatis1.3.1,做一個簡單的壓測時,出現了一個和壓力測試無關的其他的常見的問題:
org.apache.ibatis.binding.BindingException: Parameter 'stock' not found. Available parameters are [arg1, arg0, param1, param2]
	at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202) ~[mybatis-3.4.5.jar:3.4.5]
	at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45) ~[mybatis-3.4.5.jar:3.4.5]
	at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122) ~[mybatis-3.4.5.jar:3.4.5]
dao層
@Repository
public interface ProductStockDao {
  ProductStock getById(Integer id);
  void updateStockById(@Param("id") Integer id,@Param("stock")Integer stock);
}
mapper.xml
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.java4all.dao.ProductStockDao">
    <resultMap id="resMap" type="com.java4all.entity.ProductStock">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="stock"  property="stock" />
    </resultMap>

    <select id="getById" resultMap="resMap">
        SELECT * from product_stock where id = #{id}
    </select>
    <update id="updateStockById">
        UPDATE product_stock set stock = #{stock} where id = #{id};
    </update>
</mapper>
這個update方法,一直執行報錯,引數對應看著沒問題。但是解決不了問題,後來改為如下,在mapper.xml中把引數用下標來獲取,下標從0開始記,竟然好了。。。暫時不知道什麼原因,可能是mysql,mybatis,springboot其中哪一個的特定版本的坑。

修改後:

    <update id="updateStockById">
        UPDATE product_stock set stock = #{arg1} where id = #{arg0};
    </update>