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

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

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

一、描述

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

在這里插入圖片描述

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

Controller層

   /**
     * @param userId        專員的id
     * @param planState     計(jì)劃狀態(tài)
     * @param planStartTime 計(jì)劃開始時間
     * @param emtCode       公司名稱-分身id
     * @return java.util.List<com.hc360.crm.entity.po.PlanCustomer>
     * @Author zhaoxiaodong
     * @Description 高級查詢-根據(jù)計(jì)劃狀態(tài)、計(jì)劃的時間、公司名稱查詢
     * @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)為未開始的計(jì)劃
        List<CrmCustomerPlan> myPlanList = crmCustomerPlanService.selectNoStartPlan(userId);
        if (StringUtil.isNotEmpty(planStartTime)){
            //判斷計(jì)劃的開始時間和當(dāng)前時間
            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)前時間在計(jì)劃時間之后,說明過了計(jì)劃時間,這時候我們要將它的狀態(tài)改為已逾期
                    customerPlan.setPlanState(PlanStateEnum.OVERDUE.getCode());
                    overDuePlan.add(customerPlan);
                }
            }
            if (overDuePlan.size() > 0) {
                //遍歷完之后,我們就可以對數(shù)據(jù)進(jìn)行更改了
                crmCustomerPlanService.updateBatchById(overDuePlan);
            }
        }
        //接下來,就是對數(shù)據(jù)進(jìn)行查詢
        return crmCustomerPlanService.selectPlanByStateTimeCompany(limit,page,userId, planState, planStartTime, emtCode);
    }

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

Service層

    /**
    * @param userId
    * @return java.util.List<com.hc360.crm.entity.po.PlanCustomer>
    * @Author zhaoxiaodong
    * @Description 高級查詢-根據(jù)計(jì)劃狀態(tài)、時間、公司名稱查詢
    * @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層中,可以通過if和QueryWrapper實(shí)現(xiàn)動態(tài)SQL的查詢。
分頁,用到了Page對象,一定要是Mybatis的。然后調(diào)用selectPage,將對象和查詢條件傳入進(jìn)去即可。

三、 總結(jié)

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

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

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

相關(guān)文章

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

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

    這篇文章主要介紹了Java.try catch finally 的執(zhí)行順序說明,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    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à)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 使用FileReader采用的默認(rèn)編碼

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

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

    springboot如何使用mongo做日志存儲

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

    java-synchronized 嵌套使用代碼詳解

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

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

    這篇文章主要介紹了通過實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(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)試(圖文),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • 淺談一下Java中的堆和棧

    淺談一下Java中的堆和棧

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

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

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

最新評論