MyBatis dao层 方法传参有三种方法。

1. 以下标的方法获取参数。

 <update >
       INSERT ignore INTO success_killed(seckill_id,user_phone,state)VALUES (#{0},#{1},1)
 </update>

2. 以map作为dao方法中的参数,通过使用key和类型来获取参数。

<select id=" selectUser" resultMap="BaseResultMap">
   select  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>

Service层调用

Private User xxxSelectUser(){
Map paramMap=new hashMap();
paramMap.put(“userName”,”对应具体的参数值”);
paramMap.put(“userArea”,”对应具体的参数值”);
User user=xxx. selectUser(paramMap);}

3. 在dao方法中的参数里通过增加@Param("param"),在mapper中引用param来获取参数。

<update >
        <!-- 具体sql -->
        update
            seckill
        set
            number = number-1
        where seckill_id = #{seckillId}
        and start_time <![CDATA[ <= ]]> #{killTime}
        and end_time >= #{killTime}
        and number > 0;

</update>

相关文章:

  • 2021-12-29
  • 2021-10-13
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-10-08
  • 2022-01-04
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
相关资源
相似解决方案