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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Mybatis的xml配置备忘

發(fā)布時間:2025/7/14 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mybatis的xml配置备忘 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<!-- 利用hashmap傳遞參數(shù)數(shù)據(jù)查詢用戶 --><select id ="selectUserById4Map" parameterType="string" resultType="hashmap" >select<include refid ="allColumns" />from user where id = #{id}</select><!-- 利用hashmap傳遞參數(shù)數(shù)據(jù)插入用戶信息 --><select id ="insertUser4Map" parameterType="hashmap" >insert into user(id,name,age,address) values(#{id},#{name},#{age},#{address})</select><!-- 模糊查詢 --><select id ="selectUserByCondition3" parameterType="com.judy.mybatis.domain.User" resultType="com.judy.mybatis.domain.User" >select * from user where 1 = 1<if test ="id!=null" >and id = #{id}</if><if test ="name!=null" >and name like '%${name}%'</if><if test ="age!=null" >and age = #{age}</if><if test ="address!=null" >and address = #{address}</if></select>

  

<!-- 利用動態(tài)sql語句更新user數(shù)據(jù) --><insert id ="updateUserByCondition" parameterType="com.judy.mybatis.domain.User" >update user<set><if test ="name!=null" >name = #{name}</if><if test ="age!=null" >age = #{age}</if><if test ="address!=null" >address = #{address}</if></set>where id=#{id}</insert><!-- 動態(tài)seql語句查詢用戶 --><select id ="selectUserByCondition" parameterType="com.judy.mybatis.domain.User" resultType="com.judy.mybatis.domain.User" >select * from user where 1 = 1<if test ="id!=null" >and id = #{id}</if><if test ="name!=null" >and name = #{name}</if><if test ="age!=null" >and age = #{age}</if><if test ="address!=null" >and address = #{address}</if></select><!-- 動態(tài)seql語句查詢用戶方式2 --><!-- 這種方式會自動根據(jù)是否有id,如果有沒有id,那么第一個條件將不加and --><select id ="selectUserByCondition2" parameterType="com.judy.mybatis.domain.User" resultType="com.judy.mybatis.domain.User" >select * from user<where><if test ="id!=null" >id = #{id}</if><if test ="name!=null" >and name = #{name}</if><if test ="age!=null" >and age = #{age}</if><if test ="address!=null" >and address = #{address}</if></where></select>

  

<!-- 當字段很多的時候,可以通過下面這種方式抽取字段 --><sql id ="allColumns" >id,name,age,address</sql><!-- 如果在sqlMapConfig.xml中配置了別名,那么這里的resultType就可以直接寫User --><select id ="selectUserById" parameterType="string" resultMap="userMap" >select<include refid ="allColumns" />from user where id = #{id}</select>

  

轉載于:https://www.cnblogs.com/judylucky/p/7082786.html

總結

以上是生活随笔為你收集整理的Mybatis的xml配置备忘的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。