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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Mybatis 常用语句

發(fā)布時(shí)間:2024/9/27 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mybatis 常用语句 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

    • 1.結(jié)果集:
    • 2.代碼塊:
      • 2.1. 代碼塊(可被引用)
      • 2.2. 分支(if else)
    • 3.1 添加語句:
    • 3.2. 添加語句(主鍵自增,并返回主鍵)
    • 4.邏輯刪除語句:
    • 5.物理刪除語句:
    • 6.修改語句:
    • 7.查詢語句:
    • 8.動(dòng)態(tài)查詢:
    • 9.List集合遍歷
    • 10.查詢結(jié)果類型與xml屬性映射關(guān)系

1.結(jié)果集:

<resultMap id="BaseResultMap" type="xx.xxBasicPO" ><result column="id" property="id" jdbcType="BIGINT" /></resultMap>

2.代碼塊:

2.1. 代碼塊(可被引用)

<sql id="Base_Column_List" >id </sql>

2.2. 分支(if else)

<choose><when test='test1'>分支1</when><when test='test2'>分支2</when><otherwise>其他情況</otherwise></choose>

3.1 添加語句:

<insert id="MethodName" parameterType="xx.xx.POName">INSERT INTOt_name(id ,is_delete,create_user,update_user)VALUES(#{id},#{isDelete},#{createUser},#{updateUser})</insert>

3.2. 添加語句(主鍵自增,并返回主鍵)

<insert id="MethodName" parameterType="xx.xx.POName" useGeneratedKeys="true"keyProperty="id">INSERT INTOt_name(id ,is_delete,create_user,update_user)VALUES(#{id},#{isDelete},#{createUser},#{updateUser})</insert>

4.邏輯刪除語句:

<update id="MethodName" parameterType="java.util.List">update t_namesetis_delete = 1WHERE id in<foreach collection="list" item="id" open="(" separator="," close=")" >#{id}</foreach></update>

5.物理刪除語句:

<delete id="MethodName" parameterType="java.util.List">delete from t_nameWHERE id in<foreach collection="list" item="id" open="(" separator="," close=")" >#{id}</foreach></delete >

6.修改語句:

<update id="MethodName" parameterType="xx.xx.POName">UPDATE t_name <trim prefix="SET" suffixOverrides=","><if test='isDelete != null and isDelete != ""'>is_delete=#{isDelete},</if><if test='createUser != null and createUser != ""'>create_user=#{createUser},</if><if test='updateUser != null and updateUser != ""'>update_user=#{updateUser},</if></trim>WHERE id=#{id}</update>

7.查詢語句:

<select id = "MethodName" resultMap="IdOfResultMap">sql..</select >

8.動(dòng)態(tài)查詢:

select columnNm from tableNm<trim prefix="where" prefixOverrides="and|or"><if test='null != columnNm and ""!= columnNm and "1"==columnNm '>and tableNm.columnNm= #{columnNm}</if></trim>

9.List集合遍歷

<update id="deleteDetail" parameterType="java.util.List">update t_detailsetis_delete = 1WHERE id in<foreach collection="list" item="id" open="(" separator="," close=")">#{id}</foreach></update>

10.查詢結(jié)果類型與xml屬性映射關(guān)系

結(jié)果類型resultMap/resultType值
ObjectresultMap維護(hù)的Object 的resultMap結(jié)果集
List<Object>resultMap維護(hù)的Object 的resultMap結(jié)果集
StringresultTypejava.lang.String
List<String>resultTypejava.lang.String

被<![CDATA[]]>這個(gè)標(biāo)記所包含的內(nèi)容將表示為純文本:

<![CDATA[ sql ]]> 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Mybatis 常用语句的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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