一: 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. 系统---《windows + ubuntu双系统》

    安装 Windows + Ubuntu双系统 不是第一次安装 Windows + Ubuntu双系统了,每一遇见的问题都不一样,收获也不一样. 制作U盘的部分截图: 电脑的基本配置截图:

  2. 【万能的DFS和BFS基础框架】-多刷题才是硬道理!

  3. es批量导入进一对多的数据

    es批量导入进一对多的数据 我有一个产品表 一个产品对应多个属性名 一个属性名对应多个属性值 一个产品还对应一个分类名称    控制层 @ApiOperation(value = "导入所有 ...

  4. Junit加载Spring容器作单元测试

    阅读目录 > 基本的搭建 > 常见的用法 如果我们需要对我们的Service方法作单元测试,恰好又是用Spring作为IOC容器的,我们可以这么配置Junit加载Spring容器,方便做单 ...

  5. 类似于ORACLE decode 的用法

    SQL Server 2008中的写法:select t.PROJECTNAME, t.BUILDCONTENTSCALE,  CASE t.PROJECTLEVEL      WHEN '0' TH ...

  6. PL/SQL老是自动断开问题处理

    问题背景:情况是这样的,很多开发同事的plsql上班时间开着8个小时,有时候他们出去抽烟后或者中午吃完饭,回来在plsql上面执行就报错无响应,然后卡住了半天动弹不了,非得重新登录plsql才生效,我 ...

  7. 4、Spring Boot 2.x 自动配置原理

    1.4 Spring Boot 自动配置原理 简介 spring boot自动配置功能可以根据不同情况来决定spring配置应该用哪个,不应该用哪个,举个例子: Spring的JdbcTemplate ...

  8. HDU 6141 - I am your Father! | 2017 Multi-University Training Contest 8

    思路来自 FXXL 最小树形图模板用kuangbin的 /* HDU 6141 - I am your Father! [ 最小树形图 ] | 2017 Multi-University Traini ...

  9. Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

    C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...

  10. @PathVariable,@RequestParam, @RequestBody

    https://www.cnblogs.com/guoyinli/p/7056146.html https://www.cnblogs.com/zeroingToOne/p/8992746.html ...