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

MybatisPlus實(shí)現(xiàn)分頁(yè)查詢和動(dòng)態(tài)SQL查詢的示例代碼

 更新時(shí)間:2021年09月30日 12:33:46   作者:趙曉東-Nastu  
本文主要介紹了MybatisPlus實(shí)現(xiàn)分頁(yè)查詢和動(dòng)態(tài)SQL查詢的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、描述

實(shí)現(xiàn)下圖中的功能,分析一下該功能,既有分頁(yè)查詢又有根據(jù)計(jì)劃狀態(tài)、開(kāi)始時(shí)間、公司名稱進(jìn)行動(dòng)態(tài)查詢。

在這里插入圖片描述

二、實(shí)現(xiàn)方式

Controller層

   /**
     * @param userId        專員的id
     * @param planState     計(jì)劃狀態(tài)
     * @param planStartTime 計(jì)劃開(kāi)始時(shí)間
     * @param emtCode       公司名稱-分身id
     * @return java.util.List<com.hc360.crm.entity.po.PlanCustomer>
     * @Author zhaoxiaodong
     * @Description 高級(jí)查詢-根據(jù)計(jì)劃狀態(tài)、計(jì)劃的時(shí)間、公司名稱查詢
     * @Date 9:04 2021/9/29
     */
    @PostMapping("/selectPlanByStateTimeCompany")
    public Page<CrmCustomerPlan> selectPlanByStateTimeCompany(@RequestParam(required = false,defaultValue = "1")int limit, @RequestParam(required = false,defaultValue = "1")int page, @RequestParam(required = true) Long userId,@RequestParam(required = false,defaultValue = "0") int planState,@RequestParam(required = false) String planStartTime,@RequestParam(required = false) Long emtCode) {
        //獲取該專員下所有狀態(tài)為未開(kāi)始的計(jì)劃
        List<CrmCustomerPlan> myPlanList = crmCustomerPlanService.selectNoStartPlan(userId);
        if (StringUtil.isNotEmpty(planStartTime)){
            //判斷計(jì)劃的開(kāi)始時(shí)間和當(dāng)前時(shí)間
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime planTime = LocalDateTime.parse(planStartTime, dtf);
            //存放已逾期的計(jì)劃
            List<CrmCustomerPlan> overDuePlan = new ArrayList<>();
            for (CrmCustomerPlan customerPlan : myPlanList) {
                if (LocalDateTime.now().isAfter(planTime)) {
                    //當(dāng)前時(shí)間在計(jì)劃時(shí)間之后,說(shuō)明過(guò)了計(jì)劃時(shí)間,這時(shí)候我們要將它的狀態(tài)改為已逾期
                    customerPlan.setPlanState(PlanStateEnum.OVERDUE.getCode());
                    overDuePlan.add(customerPlan);
                }
            }
            if (overDuePlan.size() > 0) {
                //遍歷完之后,我們就可以對(duì)數(shù)據(jù)進(jìn)行更改了
                crmCustomerPlanService.updateBatchById(overDuePlan);
            }
        }
        //接下來(lái),就是對(duì)數(shù)據(jù)進(jìn)行查詢
        return crmCustomerPlanService.selectPlanByStateTimeCompany(limit,page,userId, planState, planStartTime, emtCode);
    }

在Controller中有l(wèi)imit、page。limit為每頁(yè)限制的數(shù)量、page為第幾頁(yè)

Service層

    /**
    * @param userId
    * @return java.util.List<com.hc360.crm.entity.po.PlanCustomer>
    * @Author zhaoxiaodong
    * @Description 高級(jí)查詢-根據(jù)計(jì)劃狀態(tài)、時(shí)間、公司名稱查詢
    * @Date 9:06 2021/9/29
    */
   @Override
   public Page<CrmCustomerPlan> selectPlanByStateTimeCompany(int limit,int page,Long userId, int planState, String planStartTime, Long emtCode) {
       Page<CrmCustomerPlan> pagelimit= new Page(page,limit);
       QueryWrapper<CrmCustomerPlan> crmCustomerPlanQueryWrapper = new QueryWrapper<>();
       crmCustomerPlanQueryWrapper.eq("create_user_id", userId);
       if (planState!=0){
           crmCustomerPlanQueryWrapper.eq("plan_state", planState);
       }
       if (StringUtil.isNotEmpty(planStartTime)){
           crmCustomerPlanQueryWrapper.eq("plan_start_time", planStartTime);
       }
       if (StringUtil.isNotEmpty(String.valueOf(emtCode))){
           crmCustomerPlanQueryWrapper.eq("emt_code", emtCode);
       }
       return crmCustomerPlanMapper.selectPage(pagelimit,crmCustomerPlanQueryWrapper);
   }

在Service層中,可以通過(guò)if和QueryWrapper實(shí)現(xiàn)動(dòng)態(tài)SQL的查詢。
分頁(yè),用到了Page對(duì)象,一定要是Mybatis的。然后調(diào)用selectPage,將對(duì)象和查詢條件傳入進(jìn)去即可。

三、 總結(jié)

MybatisPlus是真的好用,省了我們寫很多的SQL語(yǔ)句 以及配置信息
Mybatis的分頁(yè)配置信息

  /**
   * 新的分頁(yè)插件
   */
  @Bean
  public MybatisPlusInterceptor mybatisPlusInterceptor() {
      MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
      mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
      return mybatisPlusInterceptor;
  }

到此這篇關(guān)于MybatisPlus實(shí)現(xiàn)分頁(yè)查詢和動(dòng)態(tài)SQL查詢的示例代碼的文章就介紹到這了,更多相關(guān)MybatisPlus 分頁(yè)查詢和動(dòng)態(tài)SQL查詢內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java.try catch finally 的執(zhí)行順序說(shuō)明

    Java.try catch finally 的執(zhí)行順序說(shuō)明

    這篇文章主要介紹了Java.try catch finally 的執(zhí)行順序說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • Java多線程之readwritelock讀寫分離的實(shí)現(xiàn)代碼

    Java多線程之readwritelock讀寫分離的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Java多線程之readwritelock讀寫分離的相關(guān)內(nèi)容,文中涉及具體實(shí)例代碼,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-10-10
  • java?使用readLine()?亂碼的解決

    java?使用readLine()?亂碼的解決

    這篇文章主要介紹了java使用readLine()亂碼的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 使用FileReader采用的默認(rèn)編碼

    使用FileReader采用的默認(rèn)編碼

    這篇文章主要介紹了使用FileReader采用的默認(rèn)編碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • springboot如何使用mongo做日志存儲(chǔ)

    springboot如何使用mongo做日志存儲(chǔ)

    這篇文章主要介紹了springboot如何使用mongo做日志存儲(chǔ)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-06-06
  • java-synchronized 嵌套使用代碼詳解

    java-synchronized 嵌套使用代碼詳解

    本文以synchronized 的同步造成了死鎖為例,介紹了java-synchronized 嵌套使用代碼詳解,同時(shí)對(duì)鎖和死鎖的概念進(jìn)行了說(shuō)明,需要的朋友可以了解下。
    2017-09-09
  • 通過(guò)實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法

    通過(guò)實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法

    這篇文章主要介紹了通過(guò)實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Intellij IDEA基于Springboot的遠(yuǎn)程調(diào)試(圖文)

    Intellij IDEA基于Springboot的遠(yuǎn)程調(diào)試(圖文)

    這篇文章主要介紹了Intellij IDEA基于Springboot的遠(yuǎn)程調(diào)試(圖文),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • 淺談一下Java中的堆和棧

    淺談一下Java中的堆和棧

    這篇文章主要介紹了一下Java中的堆和棧,Java數(shù)據(jù)類型在執(zhí)行過(guò)程中存儲(chǔ)在兩種不同形式的內(nèi)存中:棧和堆,它們通常由運(yùn)行Java虛擬機(jī)(JVM)的底層平臺(tái)維護(hù),需要的朋友可以參考下
    2023-04-04
  • SpringBoot服務(wù)上實(shí)現(xiàn)接口限流的方法

    SpringBoot服務(wù)上實(shí)現(xiàn)接口限流的方法

    這篇文章主要介紹了SpringBoot服務(wù)上實(shí)現(xiàn)接口限流的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10

最新評(píng)論