mybatis plus foreach 的用法
一: foreach 用于 select * from tablename where colname in (A,B,C……);
1:service 层:
Set<String> teacherNums = new HashSet<>();
Set<String> departments = new HashSet<>();
list.stream().forEach(s->{
teacherNums.add(s.getTeacherNumber());
departments.add(s.getAcademeName());
}); List<GxyTeacherDto> gxyTeacherDtos = gxyTeacherMapper.selectTeaNumberBySchool(user.getOrgJson().getSchoolId(),user.getOrgJson().getSnowFlakeId(),teacherNums);
Set<String> allTeacherNum = gxyTeacherDtos.stream().map(GxyTeacherDto::getTeacherNumber).collect(Collectors.toSet()); 2: mapper 层:
List<GxyTeacherDto> selectTeaNumberBySchool(@Param("schoolId")String schoolId,@Param("snowFlakeId")Long SnowFlakeId,@Param("list") Set<String> teaNumbers); 3:xml:
<select id="selectTeaNumberBySchool" resultType="com.zhangtao.moguding.practiceservice.dto.GxyTeacherDto" >
SELECT * FROM gxy_teacher WHERE is_deleted = 0
<if test="schoolId != null and schoolId != ''">
AND school_id = #{schoolId}
</if>
<if test="snowFlakeId != null ">
AND snow_flake_id = #{snowFlakeId}
</if>
<if test="list != null and list.size >0">
AND teacher_number in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select> 二: update 多条sql
mapper 层:
int updateBatchByDefault(@Param("list") List<GxyPlanTeacherStudentEntity> teacherStudentEntities,@Param("tableName")String tableName);
xml:
<update id="updateBatchByDefault" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update <choose><when test="tableName != null and tableName !=''">${tableName}</when><otherwise>gxy_job</otherwise></choose>
<set>
plan_id = #{item.planId}
</set>
where student_id = #{item.studentId} and plan_id = #{item.defaultPlanId} and snow_flake_id = #{item.snowFlakeId} and is_deleted=0
</foreach>
</update>
item指 List<GxyPlanTeacherStudentEntity> 中的一个 GxyPlanTeacherStudentEntity 实例对象。 三: 多个查询sql union all:
impl层:
List<GxyJobEntity> jobEntitys = gxyJobMapper.selectJob(jobs);
mapper 层:
List<GxyJobEntity> selectJob(@Param("list") List<GxyJobEntity> jobs);
xml:
<resultMap type="com.zhangtao.moguding.practiceservice.entity.GxyJobEntity" id="GxyQuartersMap">
<result property="jobId" column="job_id"/>
<result property="planId" column="plan_id"/>
<result property="companyId" column="company_id"/>
<result property="jobName" column="job_name"/>
<result property="jobContent" column="job_content"/>
<result property="sector" column="sector"/>
<result property="category" column="category"/>
<result property="quartersIntroduce" column="quarters_introduce"/>
<result property="startTime" column="start_time"/>
<result property="endTime" column="end_time"/>
<result property="isMajorRight" column="is_major_right"/>
<result property="salary" column="salary"/>
<result property="state" column="state"/>
<result property="applyState" column="apply_state"/>
<result property="applyTeacherId" column="apply_teacher_id"/>
<result property="isAuto" column="is_auto"/>
<result property="oldJobId" column="old_job_id"/>
</resultMap>
<select id="selectJob" resultType="com.zhangtao.moguding.practiceservice.entity.GxyJobEntity" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=" union all">
select t1.*
from <choose><when test="item.tableName1 != null and item.tableName1 !=''">${item.tableName1}</when><otherwise>gxy_job</otherwise></choose> AS t1
<where>
<if test="item.studentId != null and item.studentId != ''">
AND t1.student_id = #{item.studentId}
</if>
<if test="item.planId != null and item.planId != ''">
AND t1.plan_id = #{item.planId}
</if>
<if test="item.snowFlakeId != null">
AND t1.snow_flake_id = #{item.snowFlakeId}
</if>
and t1.state=1 and t1.is_deleted=0
</where>
</foreach>
</select>
mybatis plus foreach 的用法的更多相关文章
- mybatis中foreach的用法(转)
foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...
- 【mybatis 的foreach的用法】
foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...
- mybatis的foreach写用法
一.mybatis查询 public abstract List<Model> findByIds(@Param("ids")List<Integer> i ...
- mybatis中foreach的用法以及特殊的情况的用法
foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separator,close. ...
- Mybatis动态SQL——if,where,trim,choose,set.foreach的用法
知识点:主要介绍mybatis中,动态sql中的if,where,trim,set,foreach的用法 自学谷粒学院mybatis学习视频,参考mybatis官方文档 java包:log4j.jar ...
- MyBatis中foreach循环的用法
一.在了解foreach之前,先了解一下mybatis传入参数及parameterType 1.我们在Dao层向对应的mapper.xml文件传递参数时,可以传递的参数有: ①.基本数据类型(如int ...
- mybatis之foreach用法
在做mybatis的mapper.xml文件的时候,我们时常用到这样的情况:动态生成sql语句的查询条件,这个时候我们就可以用mybatis的foreach了 foreach元素的属性主要有item, ...
- Mybatis foreach的用法
本文援引:https://www.cnblogs.com/fnlingnzb-learner/p/10566452.html 在做mybatis的mapper.xml文件的时候,我们时常用到这样的情况 ...
- SpringMVC +mybatis+spring 结合easyui用法及常见问题总结
SpringMVC +mybatis+spring 结合easyui用法及常见问题总结 1.FormatString的用法. 2.用postAjaxFillGrid实现dataGrid 把form表单 ...
随机推荐
- 通用mapper接口已经写好的 根据 list 集合查询 相应数据
package tk.mybatis.mapper.additional.idlist; import org.apache.ibatis.annotations.Param; import org. ...
- MacOS下安装unicorn这个库失败
因为在Mac下安装pwntools,发现安装unicorn库的时候失败了,编译报错如下 make: *** [qemu/config-host.h-timestamp] Error 1 error: ...
- No package libmcrypt available.
Centos安装PHP时,安装php依赖包时yum install libmcrypt libmcrypt-devel,报错如下: No package libmcrypt available. No ...
- [转载]es6 Promise.resolve()方法
es6 Promise.resolve()方法 2018-01-27 22:29:06 ixygj197875 阅读数 16925更多 分类专栏: ES6标准入门 (阮一峰) ES6标准入门 Pr ...
- vulkan的subpass
最近在写 unity上 vulkan开subpass 似乎pc上subpass 的input attachement hlslcc_fbinput_0绑不上的 在手机上能绑上 说明subpass这个功 ...
- 2019HDU多校第六场 6641 TDL——乱搞&&思维题
题意 设 $f(n, m)$ 为大于 $n$ 且与 $n$ 互质的数中第 $m$ 小的数,求满足 $(f(n, m) - n) \oplus n = k$ 的最小正整数 $n$ 分析 因为 $m \l ...
- JAVA的带参数的方法
一.带参数的方法 1.1 语法: <访问修饰符> 返回类型 <方法名>(<形式参数列表>) { //方法的 ...
- 安裝開源BBS軟件YAF時碰到的問題
1.下載 http://yetanotherforum.net/download.aspx 安裝說明 http://www.drreddys.com/quest/readme.htm 其實只要打開根目 ...
- OI 常用模板 手写
线性筛素数 (例题 洛谷P3383) bool p[50000010]; int cnt = 0; int prime[10000010]; inline void init() { int N = ...
- 7月清北学堂培训 Day 3
今天是丁明朔老师的讲授~ 数据结构 绪论 下面是天天见的: 栈,队列: 堆: 并查集: 树状数组: 线段树: 平衡树: 下面是不常见的: 主席树: 树链剖分: 树套树: 下面是清北学堂课程表里的: S ...