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中使用循环遍历的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql数据库(10):数据 备份
- 下一篇: R 安装详解