标签:
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>
标签:
原文地址:http://www.cnblogs.com/yangfei-beijing/p/5608061.html