MyBatis映射配置文件中参数引用表达式

 * 使用MyBatis进行数据操作时,可能需要一些参数,那么在映身的配置文件中如何引用参数呢?

 * parameter 参数说明:

 * 1.参数是数组时,配置xml,array[0]和array[1]是数组中第2个和每2个元素。

 <select id="selectByArrayParam" parameterType="map"    resultMap="BaseResultMap">

    select * from person where name =#{array[0],jdbcType=VARCHAR} and birthday=#{array[1],jdbcType=DATE}

 </select>

 2.参数是List时,配置xml,list[0]和list[1] 是列表中第1个和第2个元素。

 <select id="selectByListParam" parameterType="map" resultMap="BaseResultMap">

    select * from person where name =#{list[0],jdbcType=VARCHAR} and birthday=#{list[1],jdbcType=DATE}

 

 </select>

 3.参数是Map时,配置xml, param1和param2 是Map的key名

 <select id="selectByMapParam" parameterType="map" resultMap="BaseResultMap">

    select * from person where name =#{param1,jdbcType=VARCHAR} and birthday=#{param2,jdbcType=DATE}

 </select>

4.参数是Bean时,配置xml, id、name、identityNumber,sex、birthday、 stature是bean的属性名

 

 <insert id="insertPerson" parameterType="com.Person">

 insert into person (id, name, identity_number,

 sex, birthday, stature)

 values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{identityNumber,jdbcType=INTEGER},

 #{sex,jdbcType=CHAR}, #{birthday,jdbcType=DATE}, #{stature,jdbcType=REAL})

 </insert>

 

 

 5. 在配置的xml中,_parameter指参数对象

 <if test="_parameter != null" >

    <include refid="Example_Where_Clause" />

 </if>

 *

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值