一: 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. PAT Advanced 1008 Elevator (20 分)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

  2. 《流畅的Python》Data model(数据/对象模型)

    第一章 Data model ⚠️整本书都是讲解Data model,第一章是一个概述. ⚠️不适合初学者.因为special method和meta programming技巧只是Python代码的 ...

  3. thinkphp session跨域

    1 .在config.PHP中添加 'SESSION_OPTIONS'=>array('domain'=>'.caizhimofang.con'),//session配置    'COOK ...

  4. Redis键值设计(转载)

    参考资料:https://blog.csdn.net/iloveyin/article/details/7105181 丰富的数据结构使得redis的设计非常的有趣.不像关系型数据库那样,DEV和DB ...

  5. chrome插件编写中需要了解的几个概念和一些方法

    1.插件文件结构 1.1.manifest.json 每一个扩展.可安装的WebApp.皮肤,都有一个JSON格式的manifest文件,里面存放重要的插件相关信息. 一个最基本的配置例子: { &q ...

  6. C语言学习系列(四)C语言基本语法和数据类型

    一.基本语法 C的令牌(Tokens) C 程序由各种令牌组成,令牌可以是关键字.标识符.常量.字符串值,或者是一个符号. 关键字(保留字) auto else long switch break e ...

  7. C#读取App.config/Web.config

    读取需要添加 System.Configuration 引用, 两种方式添加: 1:.NETFramework程序可以在引用右击添加引用,然后添加System.Configuration 2:引入Nu ...

  8. .net常用属性

    1.   在ASP.NET中专用属性:               获取服务器电脑名:Page.Server.ManchineName               获取用户信息:Page.User   ...

  9. @Component,@Service,@Controller,@Repository

    1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...

  10. codeforces1213G Path Queries 并查集

    题意 给定n个结点的树,每条边有边权,有m个询问,每个询问给一个\(q_i\)输出树上有多少点对的简单路径上最大的边权不超过\(q_i\). 分析 用并查集维护点集,同时维护大小. 将所有边按边权排序 ...