mybatis关于传递参数问题

在MyBatis的select、insert、update、delete这些元素中都提到了parameterType这个属性。MyBatis现在可以使用的parameterType有基本数据类型和JAVA复杂数据类型

  • 基本数据类型:包含int,String,Date等。基本数据类型作为传参,只能传入一个。通过#{参数名} 即可获取传入的值
  • 复杂数据类型:包含JAVA实体类、Map。通过#{属性名}或#{map的KeyName}即可获取传入的值

1·基本数据类型:

 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from charge_way_tbl
    where id = #{id,jdbcType=INTEGER}
  </select>

与之对应的接口为:
 ChargeWay selectByPrimaryKey(Integer id);

2·复杂的数据类型:

分页信息:

<select id="search" resultType="map" parameterType="com.jewery.bean.ChargewayBean" >
    select 
    <include refid="Base_Column_List" />
    from charge_way_tbl
    where 1 = 1
    <if test="stylename != ''">
    	and stylename like '%${stylename}%'
    </if>
    limit #{start,jdbcType=INTEGER},#{rows,jdbcType=INTEGER}
  </select>

与之对应的接口为:

List search(ChargewayBean chargewayBean);

另外mybatis还有另外一种形式,使用注解来注入多个参数的方式,这种方式需要在接口中使用@param

<select id="getCountByParams" resultType="java.lang.Integer">
    select count(*)
    from charge_way_tbl
    where 1 = 1
    <if test="stylename != ''">
    	and stylename like '%${stylename}%'
    </if>
  </select>

此时与之对应的接口为:

int getCountByParams(@Param("stylename") String stylename);



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值