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>

 *

猜你喜欢

转载自java12345678.iteye.com/blog/2103363