zoukankan      html  css  js  c++  java
  • mybatis动态查询,模糊查询

    mybatis动态查询,模糊查询

    第一种:直接动态sql注解的形式

    @Select("<script>"
            +"select * from problem where pro_res=0 and pro_state=#{state}  "
            +"      <if test='name != null' >   "
            +"     and app_id in (select app_id from application where app_name like '%${name}%' )"
            +"      </if>"
            +"      <if test='title != null' >   "
            +"            and pro_title like '%${title}%' "
            +"      </if>"
            +"      <if test='level != null' >"
            +"            and pro_level=#{level} "
            +"      </if>"
            +"      <if test='industry != null' >"
            +"            and pro_industry like '%${industry}%' "
            +"      </if>"
            +"      <if test='company != null' >"
            +"            and pro_company like '%${company}%' "
            +"      </if>"
            +"      <if test='keyword != null' >"
            +"            and pro_keyword like '%${keyword}%' "
            +"      </if>"
            +"</script>")
    @ResultMap("problemMap")
    List<Problem> searchByConditions(String name, @Param("title") String title, String level, String industry, String company, String keyword,@Param("state") String state);
    

    第二种,基于Example的,适合于单个表的条件查询,模糊查询

    @Override
    public List<Subject> searchByConditions(String name, String degree, String title, String field, String institute) {
        SubjectExample subjectExample=new SubjectExample();
        SubjectExample.Criteria or = subjectExample.or();
        if (StringUtils.isNotBlank(name)){
            or.andSubNameLike("%"+name+"%");
        }
        if (StringUtils.isNotBlank(degree)){
            or.andSubEducationLike(degree);
        }
        if (StringUtils.isNotBlank(title)){
            or.andSubHeadLike("%"+title+"%");
        }
        if (StringUtils.isNotBlank(field)){
            or.andSubFieldLike("%"+field+"%");
        }
        if (StringUtils.isNotBlank(institute)){
            or.andSubWorkplaceLike("%"+institute+"%");
        }
        return subjectMapper.selectByExample(subjectExample);
    }
    
    博客网站 https://yamon.top 个人网站 https://yamon.top/resume GitHub网站 https://github.com/yamonc 欢迎前来访问
  • 相关阅读:
    BZOJ 3513: [MUTC2013]idiots(fft)
    BZOJ 2194: 快速傅立叶之二(fft)
    BZOJ 3779: 重组病毒(线段树+lct+树剖)
    LUOGU P3723 [AH2017/HNOI2017]礼物 (fft)
    CF 622F (拉格朗日插值)
    LUOGU P4781 【模板】拉格朗日插值
    bzoj 4184 shallot——线段树分治+线性基
    51nod 1673 树有几多愁——虚树+状压DP
    bzoj 3611(洛谷 4103) [Heoi2014]大工程——虚树
    bzoj 2286(洛谷 2495) [Sdoi2011]消耗战——虚树
  • 原文地址:https://www.cnblogs.com/chenyameng/p/12551111.html
Copyright © 2011-2022 走看看