欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MyBatis如何進(jìn)行雙重foreach循環(huán)

 更新時(shí)間:2022年02月08日 11:14:29   作者:harden_no1  
這篇文章主要介紹了MyBatis如何進(jìn)行雙重foreach循環(huán),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

進(jìn)行雙重foreach循環(huán)

mapname是一個(gè)Map<String,Map<String,Object>> 對(duì)象

<foreach collection="mapname" index="key1" item="value1" separator=",">
?? ?<foreach collection="value1" index="key2" item="value2" separator=",">
?? ??? ?#{key1},
?? ??? ?#{key2},
?? ??? ?#{value2}
?? ?</foreach>
</foreach>

使用場(chǎng)景

比如說一個(gè)付款人下面對(duì)應(yīng)的運(yùn)單的金額,那么key1就是付款人編號(hào),key2是運(yùn)單編號(hào),value2是分?jǐn)偟慕痤~ 

mybatis foreach循環(huán),傳入多個(gè)參數(shù)

上代碼

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("分頁(yè)獲取信息出錯(cuò)", e);
            return new ExceptionReturn(e);
        }
    }

mapper

/**
? ? ?* 描述:根據(jù)工種查詢列表
? ? ?* @param jobCategorys
? ? ?* @return
? ? ?*/
? ? List<WebsitesJob> findPage(@Param("jobCategorys") List<Integer> jobCategorys,@Param("ids") List<Integer> ids,@Param("workPlace") List<String> workPlace);

xml

<!-- 前臺(tái)查詢列表 -->
   <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>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論