mybatisforeach循环,传入多个参数

上代码:

controller:

@RequestMapping(value = "/findPage", method = RequestMethod.POST)
    @ResponseBody
    public Object findPage(@RequestParam(required=false) String jobCategory,@RequestParam(required=false) String ids,@RequestParam(required=false) String cities) {
        try {
            List<Integer> listJob = new ArrayList<Integer>();
            List<Integer> listIds = new ArrayList<Integer>();
            List<String> listCities = new ArrayList<String>();
            //按照城市名称和工种查询
            if(StringUtils.isNotBlank(jobCategory) && StringUtils.isNotBlank(cities)){
                String[] temp = jobCategory.split(",");
                String[] cityTemp = cities.split(",");
                for(int i=0;i<temp.length;i++){
                    listJob.add(Integer.valueOf(temp[i]));
                }
                for(int i=0;i<cityTemp.length;i++){
                    listCities.add(cityTemp[i]);
                }
                List<WebsitesJob> list = jobService.findPage(listJob, listIds, listCities);
                return new ExtGridReturn(list.size(), list);
            }
            //按照工种查询
            if(StringUtils.isNotBlank(jobCategory)){
                String[] temp = jobCategory.split(",");
                for(int i=0;i<temp.length;i++){
                    listJob.add(Integer.valueOf(temp[i]));
                }
            }
            //按照职位名称查询
            if(StringUtils.isNotBlank(ids)){
                String[] temp = ids.split(",");
                for(int i=0;i<temp.length;i++){
                    listIds.add(Integer.valueOf(temp[i]));
                }
            }
            //按照城市查询
            if(StringUtils.isNotBlank(cities)){
                String[] temp = cities.split(",");
                for(int i=0;i<temp.length;i++){
                    listCities.add(temp[i]);
                }
            }
            List<WebsitesJob> list = jobService.findPage(listJob, listIds, listCities);
            return new ExtGridReturn(list.size(), list);
        } catch (Exception e) {
            LOGGER.error("分页获取信息出错", e);
            return new ExceptionReturn(e);
        }
    }

mapper

/**
     * 描述:根据工种查询列表
     * @param jobCategorys
     * @return
     */
    List<WebsitesJob> findPage(@Param("jobCategorys") List<Integer> jobCategorys,@Param("ids") List<Integer> ids,@Param("workPlace") List<String> workPlace);

xml

<!-- 前台查询列表 -->
   <select id="findPage" resultType="cn.edu.hbcf.plugin.websites.pojo.WebsitesJob">
           select n.ID id,
              n.NAME name,
              n.WORKPLACE workPlace,
              n.JOBCATEGORY jobCategory,
              n.SALARY salary,
              n.RESPONSIBILITIES responsibilities,
              n.REQUIREMENTS requirements,
              n.ISHOT isHot,
              n.UPDATEDATE updateDate,
              n.UPDATEUSER updateUser,
              u.real_name updateName
         from websites_job n
         left join base_users u on n.updateUser = u.account
         <where>
             <if test="jobCategorys.size()!=0">
                 or    n.jobCategory in
                   <foreach collection="jobCategorys" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="ids.size()!=0">
                or n.id in
                   <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
             </if>
             <if test="workPlace.size()!=0">
                or n.WORKPLACE in
                   <foreach collection="workPlace" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
             </if>
         </where>
         order by n.ISHOT,n.ID desc
   </select>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值