序文
MyBatis Mapperファイルの選択、挿入、更新、および削除要素には、マッパーインターフェイスメソッドで受け入れられた対応するパラメータータイプに使用されるパラメータ型属性があります。この記事では、主にMyBatisのパラメーターパラメータータイプに関する関連コンテンツを紹介します。参照と学習のために共有されます。以下ではあまり言いません。詳細な紹介を一緒に見てみましょう。
1. mybatisのパラメータ型タイプは2つのタイプに分割されます
1。1。基本データ型:int、string、long、date;
1。2。複雑なデータ型:クラスとマップ
2。パラメーターで値を取得する方法:
2.1基本データ型:#{パラメーター}パラメーターで値を取得します
2.2複雑なデータ型:#{属性名}、#{key}マップ
3。ケース:
3.1基本データ型のケース
<sql id = "base_column_list"> id、car_dept_name、car_maker_name、icon、car_maker_py、hot_type < /sql> <selecty id = "selectbyprimarykey" resurectmap = "baseresultmap" parametertype = "basist =" basing "> select" common_car_make id =#{id、jdbctype = bigint} </select>3.2複雑なタイプマップタイプ
<select id = "querycarmakerlist" resultmap = "baseeresultmap" 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 =######= < /> < />>> fide test = "cardeptname!= null"> and cm.car_dept_name =#{cardeptname、jdbctype = varchar} </if> <if test = "carmakername!= null"> and cmaker_name =#{carmakername、jdbctype = nulr " cm.hot_type =#{hottype、jdbctype = bigint} </if> cmid </select>3.3複雑なタイプクラスタイプ
<update id = "updatebyprimarykeyselective" parametertype = "com.epeit.api.model.commoncarmake"> update common_car_make <set> <if test = "cardeptname!= null"> car_dept_name =##{cardepname、jdbctype = nif> </< car_maker_name =#{carmakername、jdbctype = varchar}、</if> <if> <if> "icon!= null"> icon = {icon、jdbctype = varchar}、</if> <if> <if> <if> <"carmakerpy!= null"> carmakerpe =##{karmakerpe、jdbctype、jdbctype <if test = "hottype!= null"> hot_type =#{hottype、jdbctype = bigint}、</if> </set>ここで、id =#{id、jdbctype = bigint} </update>3.4複雑なタイプ - アレイがマップに含まれるケース
<選択id = "selectproorderbyorderid" resulttype = "com.epeit.api.model.proorder" parametertype = "java.util.hashmap"> select sum(pro_order_num)proordernum、product_id productid、promoris_id promionsid item = "item" open = "order_id in(" separator = "、" close = ")">#{item、jdbctype = bigint} </foreach> </if> group by product_id、promotion_id </select>4。Annotation@Param:これは非常に特別ですが、理解するのは簡単です
ケース1:
@Param(value="startdate") String startDate :単一のプロパティに注釈を付けます。これは、パラメーターを1回変更することに似ています
たとえば、 *mapper.xmlでsqlステートメント(daoレイヤー)を構成しますmybatisを呼び出す
List <String> SelectIDBySortTime(@Param(value = "startDate")String startDate);
次に、XMLのステートメントを@paramブラケットのコンテンツと一致させる必要があります:パラメーターはStartDateです
<選択id = "selectidbysorttime" resulttype = "java.lang.string" parametertype = "java.lang.string"> select select ajlcid from ebd_fh_ajlc where serttime> = to_date(#{startdate、jdbctype = varchar}、 'yyyymmdted') keyvalue in(ebd_fh_company_listからselect distince companyname where isupdate = '0')</select>ケース2:
注釈javabean、@param(value = "datevo")datevo datevo;書かれたパラメーターに注意を払う必要があります
List <String> selectids(@param(value = "datevo")datevovo);
対応するマッピングファイル
<select id = "selectids" resultType = "java.lang.string" parametertype = "com.api.entity.datevo"> select ebd_fh_ajlcから別個のajlcidを選択> = to_date(#{datevo.startdate、jdbctype = varchar}、 'yyymmdd') created_date = updated_dateおよびkeyvalue in(ebd_fh_company_listからselect dixtionce companyname where isupdate = '0')</select>利点と短所に関しては、それはあなたの個人的な好みに依存します
要約します
上記は、この記事のコンテンツ全体です。この記事の内容には、すべての人の研究や仕事に特定の参照値があることを願っています。ご質問がある場合は、メッセージを残してコミュニケーションをとることができます。 wulin.comへのご支援ありがとうございます。