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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

for循环执行 mybatis_Mybatis中使用循环遍历

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 for循环执行 mybatis_Mybatis中使用循环遍历 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Mybatis中傳參數的方法

1.使用注解綁定,mapper.xml 對應方法 不需要指定?parameterType,(推薦使用注解綁定方式)

方法接口:

List selectByExample(@Param("example") CalculateIdeacommissionsum example,@Param("roleNameList") List roleNameList);

方法對應的Mapper.xml

select

id, calculateYear, calculateMonth, userId, userCode, userName, userStatus, companyName,

companyId, curDeptId, curDeptName, roleName from Calculate_IdeaCommissionSum

where calculateYear=#{example.calculateYear,jdbcType=SMALLINT}

and calculateMonth=#{example.calculateMonth,jdbcType=SMALLINT}

and deleteFlag=#{example.deleteFlag,jdbcType=TINYINT}

#{rolename,jdbcType=VARCHAR}

order by userStatus

2.如果接口參數沒有使用注解綁定,mapper.xml 對應方法?需要指定對應的參數類型。

List selectByExample(CalculateIdeacommissionsum example);

方法對應的Mapper.xml

select

id, calculateYear, calculateMonth, userId, userCode, userName, userStatus, companyName,

companyId, curDeptId, curDeptName, roleName from Calculate_IdeaCommissionSum

where calculateYear=#{calculateYear,jdbcType=SMALLINT}

and calculateMonth=#{calculateMonth,jdbcType=SMALLINT}

order by userStatus

3.?parameterType 也可以使用Map存放參數進行查詢

接口方法:

List selectByParam(Map map);

接口方法對應的Mapper.xml 文件方法:

select * from Base_EmpInfo

where deleteFlag=0

and userName=#{userName,jdbcType=VARCHAR}

4.mybatis 遍歷循環

collection標識我們程序傳值過來的集合

open表示我們遍歷的集合以什么字符開始

close表示我們遍歷的集合以什么字符結尾

item是給我們集合遍歷取一個變量

separator 表示的是分隔符,將我們集合中遍歷出來的數據用","分隔開。

#{rolename,jdbcType=VARCHAR}

sql如下:

select * from Calculate_IdeaCommissionSum where calculateYear=2019 and calculateMonth=2 and roleName? in ('副總經理','總監','經紀人');

將roleName的多個條件用關系轉化為 roleName in (roleName1,roleName2,roleName3...)??in中用foreach循環

總結

以上是生活随笔為你收集整理的for循环执行 mybatis_Mybatis中使用循环遍历的全部內容,希望文章能夠幫你解決所遇到的問題。

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