激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - MyBatis中傳入?yún)?shù)parameterType類型詳解

MyBatis中傳入?yún)?shù)parameterType類型詳解

2021-04-24 11:51袁義銳 Java教程

這篇文章主要給大家介紹了關(guān)于MyBatis中傳入?yún)?shù)parameterType類型的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

前言

mybatis的mapper文件中的select、insert、update、delete元素中有一個(gè)parametertype屬性,用于對應(yīng)的mapper接口方法接受的參數(shù)類型。本文主要給大家介紹了關(guān)于mybatis傳入?yún)?shù)parametertype類型的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧。

1. mybatis的傳入?yún)?shù)parametertype類型分兩種

   1. 1. 基本數(shù)據(jù)類型:int,string,long,date;

   1. 2. 復(fù)雜數(shù)據(jù)類型:類和map

2. 如何獲取參數(shù)中的值:

   2.1  基本數(shù)據(jù)類型:#{參數(shù)} 獲取參數(shù)中的值

   2.2  復(fù)雜數(shù)據(jù)類型:#{屬性名}  ,map中則是#{key}

3.案例:

 3.1 基本數(shù)據(jù)類型案例

?
1
2
3
4
5
6
7
8
9
<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 復(fù)雜類型--map類型    

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<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 復(fù)雜類型--類類型

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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 復(fù)雜類型--map中包含數(shù)組的情況

?
1
2
3
4
5
6
7
8
9
10
11
12
<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:這個(gè)比較特殊,但是很好理解

案例一:

@param(value="startdate") string startdate :注解單一屬性;這個(gè)類似于將參數(shù)重命名了一次

如調(diào)用mybatis的*mapper.xml中配置sql語句(dao層)

?
1
list<string> selectidbysorttime(@param(value="startdate")string startdate);

則xml中的語句,需要配合@param括號中的內(nèi)容:參數(shù)為startdate

?
1
2
3
4
<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>

案例二:

注解javabean,@param(value="datevo") datevo datevo;則需要注意編寫的參數(shù)

?
1
list<string> selectids(@param(value="datevo")datevo datevo);

對應(yīng)的mapping文件

?
1
2
3
4
<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>

至于要說優(yōu)缺點(diǎn)的話,看個(gè)人喜好

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對服務(wù)器之家的支持。

原文鏈接:https://blog.csdn.net/u010235716/article/details/51698422

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: julieann艳星激情办公室 | 在线小视频国产 | 成人在线精品视频 | 久久综合给合久久狠狠狠97色69 | 亚洲国产综合在线观看 | 免费看成年人视频在线 | 91在线视频网址 | 久久免费视频在线 | 性欧美videos另类极品 | 福利一区二区三区视频在线观看 | 欧美毛片在线观看 | av7777777 | 精品亚洲一区二区三区 | 久久中出 | 成人毛片在线免费看 | 一区二区三区无码高清视频 | 色妞妞视频 | 91午夜少妇三级全黄 | 毛片大全在线观看 | 狠狠干b| 欧美成人理论片乱 | 欧美综合在线观看 | 精品国产一区二区三区在线观看 | 黄色免费在线电影 | 欧美综合在线观看视频 | 黄色av网 | 国产视频精品在线 | 久久精品com | 中文字幕免费一区 | 在线观看av国产一区二区 | 一区二区三区视频在线观看 | 在线成人免费视频 | 中国杭州少妇xxxx做受 | 国产成人精品免高潮在线观看 | 日产精品久久久久久久 | 鲁丝一区二区二区四区 | 亚洲资源网| 精品国产99久久久久久宅男i | 成人福利在线免费观看 | 久久久一区二区三区精品 | 国产精品亚洲一区二区三区久久 |