孤独海岸线 发表于 2016-11-27 13:04:24

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

  * 使用MyBatis进行数据操作时,可能需要一些参数,那么在映身的配置文件中如何引用参数呢?
  * parameter 参数说明:
  * 1.参数是数组时,配置xml,array和array是数组中第2个和每2个元素。
  <select id="selectByArrayParam" parameterType="map"    resultMap="BaseResultMap">
  select * from person where name =#{array,jdbcType=VARCHAR} and birthday=#{array,jdbcType=DATE}
  </select>
  2.参数是List时,配置xml,list和list 是列表中第1个和第2个元素。
  <select id="selectByListParam" parameterType="map" resultMap="BaseResultMap">
  select * from person where name =#{list,jdbcType=VARCHAR} and birthday=#{list,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>
  *
页: [1]
查看完整版本: MyBatis映射配置文件中参数引用表达式