首页 > 作文

lambdaQueryWrapper多条件嵌套查询方式

更新时间:2023-04-04 13:44:08 阅读: 评论:0

目录
lambdaquerywrapper多条件嵌套查询表结构如下下面是根据条件生成的sql语句lambdaquerywrapper 常用条件

lambdaquerywrapper多条件嵌套查询

需求:根据条件获取一段时期内按照年份和周存储的数据

表结构如下

urnettypemodulenamecitynamesubjectcnamesubjectenamepvuvyearweek11江苏省死神专题sszt1007020195111江苏省海贼王专题hzwzt2008020195211江苏省火影忍者专题hyrzzt30090202001
/**     * @param pagenum     当前页     * @param pagesize    每页条数     * @param modulename  产品     * @param urnettype 运营商     * @param cityname    城市名称     * @param begintime   开始周的任意一天日期(例如:2019-12-20)     * @param endtime     结束周的任意一天日期(例如:2020-01-20)     * @param keyword     查询条件(专题英文名或者中文名)     * @return     */        //开始年份        string beginyear = null;        //结束年份        string endyear = null;        //开始周数        string beginweek = null;        //结束周数        string endweek = null;        /*这部分内容忽略,调用了其他的方法,         反正就是为了获取开始日期所在的年份、周数以及结束日期所在的年份、周数*/        if (stringutils.isblank第三英语怎么说(begintime) || stringutils.isblank(endtime)) {            datetime datetime = dateutil.lastweek();            //格式化日期,结果:yyyymmdd            begintime = dateutil.formatdate(datetime);            beginyear = timeutils.getdateofyearweek(begintime).get("year");            endyear = beginyear;            beginweek = timeutils.getdateofyearweek(begintime).get("week");            endweek = beginweek;        } el {            beginyear = timeutils.getdateofyearweek(begintime).get("year");            endyear = timeutils.getdateofyearweek(endtime).get("year");            beginweek = timeutils.getdateofyearweek(begintime).get("week");            endweek = timeutils.getd关于文明的故事ateofyearweek(endtime).get("week");        }        page<dwsubjectdatainfoww> page = new page<>(pagenum, pagesize);        lambdaquerywrapper<dwsubjectdatainfoww> querywrapper = wrappers.<dwsubjectdatainfoww>lambdaquery();        if (be留园ginyear.equals(endyear)) {            querywrapper.eq(dwsubjectdatainfoww::getyearbecauof, beginyear);            querywrapper.between歌曲爱情这杯酒谁喝都得醉(dwsubjectdatainfoww::getweek, beginweek, endweek);        } el {            //因为java8 lambda表达式中最终变量问题,重新赋值一个参数解决            string year1 = beginyear;            string year2 = endyear;            string week1 = beginweek;            string week2 = endweek;            querywrapper.and(wrapper -> wrapper.and(wrapper1 -> wrapper1.eq(dwsubjectdatainfoww::getyear, year1).ge(dwsubjectdatainfoww::getweek, week1))                    .or(wrapper2 -> wrapper2.eq(dwsubjectdatainfoww::getyear, year2).le(dwsubjectdatainfoww::getweek, week2)));        }        querywrapper.orderbydesc(dwsubjectdatainfoww::getyear);        querywrapper.orderbydesc(dwsubjectdatainfoww::getweek);        if (strutil.isnotempty(cityname)) {            querywrapper.eq(dwsubjectdatainfoww::getcityname, cityname);        }        if (strutil.isnotempty(urnettype)) {            querywrapper.eq(dwsubjectdatainfoww::geturnettype, urnettype);        }        if (strutil.isnotempty(modulename)) {            querywrapper.eq(dwsubjectdatainfoww::getmodulename, modulename);        }        //搜索条件可以是专题中文名或英文名        if (strutil.isnotempty(keyword)) {            querywrapper.and(wrapper -> wrapper.like(dwsubjectdatainfoww::getsubjectcname, keyword).or().like(dwsubjectdatainfoww::getsubjectename, keyword));        }        try {            page<dwsubjectdatainfoww> list = dwsubjectdatainfowwrvice.page(page, querywrapper);            return ajaxresult.success(list);        } catch (exception e) {            logger.error("获取分周专题数据列表错误,错误信息为:", e);            return ajaxresult.error();        }

下面是根据条件生成的sql语句

where    (        (            (year = ? and week >= ?)            or (year = ? and week <= ?)        )        and city_name = ?        and ur_net_type = ?        and module_name = ?        and (            subject_cname like ?            or subject_ename like ?        )    )order by    year desc,    week desc

lambdaquerywrapper 常用条件

以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。

本文发布于:2023-04-04 13:44:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/9e10576b57659133c4eaf7b61a90a697.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:lambdaQueryWrapper多条件嵌套查询方式.doc

本文 PDF 下载地址:lambdaQueryWrapper多条件嵌套查询方式.pdf

标签:条件   年份   专题   江苏省
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图