MyBatis3 传递参数种类

第一种:单个参数[基本类型]:

# Mapper 接口定义
T selectByPrimaryKey(String sid);

# Mapper 映射文件
 <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ***
    where sid = #{sid,jdbcType=VARCHAR}
  </select>

第二种:多个参数

# Mapper 接口定义
public List<T> getList(String sid, String code);

# Mapper 映射文件
<select id="getList" resultType="T">
  select * from ** where sid = #{0} and code= #{1}  
</select>   

第三种:Map参数

# Mapper 接口定义
List<T> selectAll(Map<String,Object> parame);

# Mapper 映射文件
<select id="selectAll" parameterType="map" resultMap="BaseResultMap">
  	select 
    <include refid="Base_Column_List" />
    from cm
    where 1 = 1
       <if test="id != null">
            and  cm.id = #{id,jdbcType=DECIMAL}
        </if>
        <if test="carDeptName != null">
            and  cm.car_dept_name = #{carDeptName,jdbcType=VARCHAR}
        </if>
        <if test="carMakerName != null">
            and  cm.car_maker_name = #{carMakerName,jdbcType=VARCHAR}
        </if>
        <if test="hotType != null" >
           and  cm.hot_type = #{hotType,jdbcType=BIGINT}
        </if>

  </select>

第四种:类参数

 <update id="updateByPrimaryKeySelective" parameterType="com.system.model.User" >
    update user
    <set >
      <if test="carDeptName != null" >
        car_dept_name = #{carDeptName,jdbcType=VARCHAR},
      </if>
      <if test="carMakerName != null" >
        car_maker_name = #{carMakerName,jdbcType=VARCHAR},
      </if>
      <if test="icon != null" >
        icon = #{icon,jdbcType=VARCHAR},
      </if>
      <if test="carMakerPy != null" >
            car_maker_py = #{carMakerPy,jdbcType=VARCHAR},
      </if>
      <if test="hotType != null" >
            hot_type = #{hotType,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

第五种:List参数

  <delete id="batchdelete" parameterType="java.util.List">
  	delete from user_relation_role where SID in 
  	<foreach item="sid" collection="list" open="(" separator="," close=")">
    	#{sid}
    </foreach>
  </delete>

第七种:@Param参数

# Mapper 接口定义
List<String> selectIdBySortTime(@Param(value="startdate")String startDate);

# Mapper 映射文件
 <select id="selectIdBySortTime" resultType="java.lang.String" parameterType="java.lang.String">
  	select distinct *** from *** where sorttime >= to_date(#{startdate,jdbcType=VARCHAR},'YYYY-MM-DD') and created_date=updated_date 
  	and keyvalue in (select  distinct companyname from *** where isupdate='0')
   </select>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值