MyBatisの----パラメータはのParameterTypeタイプで深さを通過しました

MyBatisの----パラメータはのParameterTypeタイプで深さを通過しました

序文

マッパーMyBatisのファイル選択、挿入、更新、削除のParameterType要素は、受け入れマッパーパラメータに対応するインタフェース・メソッドのタイプを性質を有しています。パラメータをご紹介するこの記事では、以下の詳細な紹介を見てみることを、言ってあまり話をしなかった、あなたの参照のための共有に学び、コンテンツのMyBatisののParameterTypeタイプを通過しました。

1. MyBatisの入ってくるのパラメータは2種類数ParameterTypeです

。\ 1 1.基本データ型:int型、文字列、長い、日付。

\ 1つの2.複合データ型:クラスと地図

パラメータの値を取得する方法2:

2.1基本データ型:パラメータ{#}は、パラメータの値を求めます

2.2複合データ型:属性名#{}、#されたマップ{キー}

3.ケース:

3.1基本データ型ケース

<sql id="Base_Column_List" > 
 id, car_dept_name, car_maker_name, icon,car_maker_py,hot_type 
 </sql> 
 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > 
 select 
 <include refid="Base_Column_List" /> 
 from common_car_make 
 where id = #{id,jdbcType=BIGINT} 
 </select>

3.2型の複合型--map

<select id="queryCarMakerList" resultMap="BaseResultMap" parameterType="java.util.Map"> 
  select 
  <include refid="Base_Column_List" /> 
  from common_car_make 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> 
  ORDER BY cm.id 
 </select>

3.3複合型 - タイプクラス

<update id="updateByPrimaryKeySelective" parameterType="com.epeit.api.model.CommonCarMake" > 
 update common_car_make 
 <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>

3.4 --map複合タイプは、状況の配列を含んでいます

<select id="selectProOrderByOrderId" resultType="com.epeit.api.model.ProOrder" parameterType="java.util.HashMap" > 
  select sum(pro_order_num) proOrderNum,product_id productId,promotion_id promotionId 
  from pro_order 
  where 1=1 
  <if test="orderIds != null"> 
   and 
   <foreach collection="orderIds" item="item" open="order_id IN(" separator="," close=")"> 
    #{item,jdbcType=BIGINT} 
   </foreach> 
  </if> 
  GROUP BY product_id,promotion_id 
 </select>

4.メモ@Param:これは、それが十分に理解され、かなり特殊です

ケースI:

@Param(value="startdate") String startDate :注釈単一のプロパティを、このパラメータには、名前を変更することが似ています

コールMyBatisの* mapper.xmlのconfigure SQL文(DAO層)として、

List<String> selectIdBySortTime(@Param(value="startdate")String startDate);

XML文と内容@param括弧に合わせて:パラメータSTARTDATE

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

ケースII:

注JavaBeanは、Paramの(値=「dateVo」)DateVo dateVo @;あなたが書かれたパラメータに注意を払うに必要

List<String> selectIds(@Param(value="dateVo")DateVo dateVo);

対応するマッピングファイル

<select id="selectIds" resultType="java.lang.String" parameterType="com.api.entity.DateVo"> 
 select distinct ajlcid from ebd_fh_ajlc where sorttime >= to_date(#  {dateVo.startDate,jdbcType=VARCHAR},'YYYY-MM-DD') and created_date=updated_date 
 and keyvalue in (select distinct companyname from ebd_fh_company_list where isupdate='0') 
 </select>

言いたいことの利点と欠点については、その後、個人の好みに依存します

概要

この記事のためにすべてをだと、私はこの論文の内容は、学ぶために誰か仕事のための学習のいくつかの基準値を願っていました

おすすめ

転載: www.cnblogs.com/XtsLife/p/12079865.html