码迷,mamicode.com
首页 > 其他好文 > 详细

多条件分组精准匹配

时间:2019-08-11 23:14:03      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:amp   group   tom   test   cti   card   collect   pen   需要   

2019-08-11

对同一条数据的不同属性分组进行过滤筛选,每一组筛选的条件组合可以有多个也可以没有。首先以一个分组中的条件进行过滤,之后另一个分组中的条件对上一个条件过滤之后的结果进行再次筛选,同理可得多分组筛选。进行第一次过滤需要前台传送第一次过滤的条件数据,多个属性同时过滤就需要将所有需要的条件的参数同时传送。

1、mapper.xml层代码展示             

 1 <select id="findRosterGroupRoster" resultType="com.example.pojo.Roster">
 2        select job_number, full_name, sex, mobile, id_type, id_card, bank_name,
 3        bank_account, register_status, type_of_work
 4        from roster where customer_id = #{customerId} 
 5        
 6        <if test="registerStatusS != null and registerStatusS.length != 0">     //传入的第一个过滤条件,同一属性可以选多种状态,所以是数组对象
 7           and register_status in <foreach collection="registerStatusS" index="index" item="registerStatus" 
 8                     open="(" separator="," close=")">
 9                 #{registerStatus}
10             </foreach>
11         </if>
12         <if test="statusS != null and statusS.length != 0">
13            and status in <foreach collection="statusS" index="index" item="status" 
14                     open="(" separator="," close=")">
15                 #{status}
16             </foreach> 
17         </if>
18          <if test="typeOfWorks != null and typeOfWorks.length != 0">
19            and type_of_work in <foreach collection="typeOfWorks" index="index" item="typeOfWork" 
20                     open="(" separator="," close=")">
21                 #{typeOfWork}
22             </foreach>
23         </if>     
24     </select>
25     

2、mapper.java层代码

 1       /**
 2      * 分组精确筛选
 3      * @param customerId
 4      * @param registerStatusS
 5      * @param statusS
 6      * @param typeOfWorks
 7      * @return
 8      */
 9     List<Roster> findRosterGroupRoster(@Param("customerId")Integer customerId, @Param("registerStatusS") Integer[] registerStatusS,
10             @Param("statusS") String[] statusS, @Param("typeOfWorks")String[] typeOfWorks);    //传入数组参数,不要忘记javabean中要进行定义
11     

 注意:从前端接收数据一定是数组类型,如下格式:

{"statusS":["157576651","15724367546",“15737756576”]}

多条件分组精准匹配

标签:amp   group   tom   test   cti   card   collect   pen   需要   

原文地址:https://www.cnblogs.com/H-Dream/p/11336975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!