一: 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 的用法的更多相关文章

  1. mybatis中foreach的用法(转)

    foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...

  2. 【mybatis 的foreach的用法】

    foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...

  3. mybatis的foreach写用法

    一.mybatis查询 public abstract List<Model> findByIds(@Param("ids")List<Integer> i ...

  4. mybatis中foreach的用法以及特殊的情况的用法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separator,close. ...

  5. Mybatis动态SQL——if,where,trim,choose,set.foreach的用法

    知识点:主要介绍mybatis中,动态sql中的if,where,trim,set,foreach的用法 自学谷粒学院mybatis学习视频,参考mybatis官方文档 java包:log4j.jar ...

  6. MyBatis中foreach循环的用法

    一.在了解foreach之前,先了解一下mybatis传入参数及parameterType 1.我们在Dao层向对应的mapper.xml文件传递参数时,可以传递的参数有: ①.基本数据类型(如int ...

  7. mybatis之foreach用法

    在做mybatis的mapper.xml文件的时候,我们时常用到这样的情况:动态生成sql语句的查询条件,这个时候我们就可以用mybatis的foreach了 foreach元素的属性主要有item, ...

  8. Mybatis foreach的用法

    本文援引:https://www.cnblogs.com/fnlingnzb-learner/p/10566452.html 在做mybatis的mapper.xml文件的时候,我们时常用到这样的情况 ...

  9. SpringMVC +mybatis+spring 结合easyui用法及常见问题总结

    SpringMVC +mybatis+spring 结合easyui用法及常见问题总结 1.FormatString的用法. 2.用postAjaxFillGrid实现dataGrid 把form表单 ...

随机推荐

  1. idou教你学Istio10 : 如何用Istio实现K8S Egress流量管理

    上一篇我们了解了如何控制入口流量,本文主要介绍在使用Istio时如何访问集群外服务,即对出口流量的管理. 默认安装的Istio是不能直接对集群外部服务进行访问的,如果需要将外部服务暴露给 Istio ...

  2. win10锁屏壁纸文件夹Assets中无文件问题的解决方法

    一.前言 win10在锁屏时会有很多精美的壁纸,在网上查找到win10锁屏壁纸存放目录为 : C:\Users\你的用户名\AppData\Local\Packages\Microsoft.Windo ...

  3. java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present

    @Controller@ComponentScan@Configuration@EnableScheduling@EnableAutoConfiguration(exclude={DataSource ...

  4. Tcp/IP协议详讲

    TCP/IP协议分层详解 目录 TCP/IP 和 ISO/OSI TCP/IP分层模型 数据的封装与分用 其他相关概念 TCP/IP 通信传输流 负责传输的 IP 协议 正文 回到顶部 TCP/IP ...

  5. SQL Server CET 通用表表达式 之 精典递归

    SQL2005 Common Table Expressions(CET)即通用表表达式. SQLSERVER CET递归使用案例: 1.普通案例 表结构如下:   ;WITH cet_depart ...

  6. Java基础 String/StringBuff/StringBuilder 常用操作方法复习/内存分析/三者的效率比较

    附:jdk1.8使用IDEA安装.创建.使用JUnit单元测试 笔记总结: /**String 复习 * 1.像C++这样的char arr[]="..." 的方式无法声明Java ...

  7. jmeter非GUI的运行命令

    jmeter 的参数 参数说明: -h 帮助 -> 打印出有用的信息并退出 -n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter -t 测试文件 -> 要运行的 JM ...

  8. 大数据之路week02 Collection 集合体系收尾(Set)

    1.Set集合(理解) (1)Set集合的特点 无序,唯一. (2)HashSet集合(掌握) A: 底层数据结构是哈希表(是一个元素为链表的数组) B: 哈希表底层依赖两个方法: hashCode( ...

  9. 如何实现UI自动化?DevExpress Winforms帮你忙

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...

  10. POP3与SMTP以及python实现邮件的发送

    什么是POP3协议: POP3是Post Office Protocol 3的简称,即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的电子协议.它是因特网 ...