日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

输入参数_MyBatis中的输入/输出参数

發(fā)布時間:2025/3/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 输入参数_MyBatis中的输入/输出参数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

MyBatis的輸入/輸出參數(shù)

輸入?yún)?shù)

MyBatis中的Dao映射配置中的parameter屬性表示輸入?yún)?shù)類型,它對應(yīng)Dao接口方法的參數(shù)類型有三種:

  • 基本數(shù)據(jù)類型:如int、char等
<insert?id="inserName"?parameterType="string">
????????insert?into?user(username)?values?(#{username})
????insert>
  • 實體類:POJO類(要輸入全限定類名,如:com.simon.domain.User)
<insert?id="inserUser"?parameterType="com.simon.domain.User">
????????insert?into?user(username,birthday,sex,address)values?(#{username},#{birthday},#{sex},#{address})
????insert>
  • 實體類包裝類
<insert?id="inserUserVO"?parameterType="com.simon.domain.UserVO">
????????insert?into?user(username,birthday,sex)values?(#{username},#{birthday},#{sex})
????insert>

輸出參數(shù)

輸出參數(shù)有兩種表現(xiàn)形式,分別為resultType和resultMap

1、resultType

resultType可以指定結(jié)果集的類型,它可以支持基本類型和實體類型

  • 基本類型
?
<select?id="findTotal"?resultType="int">?
?select?count(*)?from?user;
select>
  • 實體類
?
<select?id="findAll"?resultType="com.simon.domain.User">
?select?*?from?user
select>

2、resultMap

resultMap標(biāo)簽可以建立查詢的列名和實體類的屬性名稱不一致時建立關(guān)系,從而實現(xiàn)封裝。在 select 標(biāo)簽中使用 resultMap 屬性指定引用即可。同時 resultMap 可以實現(xiàn)將查詢結(jié)果映射為復(fù)雜類 型的 pojo,比如在查詢結(jié)果映射對象中包括 pojo 和 list 實現(xiàn)一對一查詢和一對多查詢。

  • 定義resultMap
?
<resultMap?id="userMap"?type="com.simon.domain.user">
????????
????????<id?property="userId"?column="id">id>
????????
????????<result?property="userName"?column="username">result>
????????<result?property="userAddress"?column="address">result>
????????<result?property="userSex"?column="sex">result>
????????<result?property="userBirthday"?column="birthday">result>
????resultMap>

  • 映射的配置
?
<select?id="findAll"?resultMap="userMap">??
?select?*?from?user?
select>?

原創(chuàng)不易,如果您覺得這篇文章有用,請您安排「在看」、「點贊」、「轉(zhuǎn)發(fā)」,這將是對我最大的鼓勵!

總結(jié)

以上是生活随笔為你收集整理的输入参数_MyBatis中的输入/输出参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。