mybatis在执行sql时参数问题

写mybatis的时候,遇见了这么一种情况,不知道为什么

stockDao.reducestock(og);//这里是封装一个bean
stockDao.reducestock(g.getGid(),g.getCount());//这里直接传俩参数

接口是这么写的

void reducestock(order_goods og);

void reducestock(Integer gid,Integer count);

 

这里我没有用注解,用的是配置

<update id="reducestock" parameterType="com.Utils.order_goods">
    UPDATE goods SET stock1 =stock1 - #{count} WHERE gid= #{oggid}
</update>

<update id="reducestock" parameterType="Integer">
    UPDATE goods SET stock1 =stock1 - #{count} WHERE gid= #{oggid}
</update>

结果是第一种情况可以,第二种就报错,说我count找不到。

我是初次接触ssm框架的,希望大佬能指点一下,之前就遇见过这种情况,不过写的是注解,也是直接传参不行,但是传bean就可以

 

 

直接传参数要加注解指明参数名

void reducestock(@Param("oggid")Integer gid,@Param("count")Integer count);

传入的值和接口定义的值不是一样的,最要在接口那加个 @Param,比如:   BusiConfig getBusiConfig(@Param("headerInstid") String headerInstid, @Param("busiType") String busiType);具体作用可以百度一下的

void reducestock(@Param("oggid")Integer oggid,@Param("count")Integer count);

<update id="reducestock">
    UPDATE goods SET stock1 =stock1 - #{count} WHERE gid= #{oggid}
</update>

这样就可以了 去掉parameterType="Integer"