zoukankan      html  css  js  c++  java
  • MyBatis dao层 方法传参

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

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

     <update id="insertSuccessKilled">
           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 id="reduceNumber">
            <!-- 具体sql -->
            update
                seckill
            set
                number = number-1
            where seckill_id = #{seckillId}
            and start_time <![CDATA[ <= ]]> #{killTime}
            and end_time >= #{killTime}
            and number > 0;

    </update>

  • 相关阅读:
    re | [SWPU2019]ReverseMe
    wp | re | 2020“巅峰极客”网络安全技能挑战赛
    re | [CFI-CTF 2018]IntroToPE
    re | [FlareOn1]Bob Doge
    re | [ACTF新生赛2020]SoulLike
    re | [GKCTF2020]Chelly's identity
    ospf配置与ofps选举DR/BDR
    静态路由的配置
    配置三层交换机实现vlan间通信
    hybrid接口
  • 原文地址:https://www.cnblogs.com/yangfei-beijing/p/5608061.html
Copyright © 2011-2022 走看看