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

使用LambdaQueryWrapper動態(tài)加過濾條件?動態(tài)Lambda

 更新時間:2022年01月11日 08:58:14   作者:陜西小伙伴網(wǎng)絡(luò)科技有限公司  
這篇文章主要介紹了使用LambdaQueryWrapper動態(tài)加過濾條件?動態(tài)Lambda,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教。

LambdaQueryWrapper動態(tài)加過濾條件 動態(tài)Lambda

1、遇到這樣的需求,在baseservice類中處理數(shù)據(jù)權(quán)限,子類可能使用QueryWrapper或者LambdaQueryWrapper調(diào)用base類的方法進行查詢。

2、可以拿到的:PO的類,數(shù)據(jù)權(quán)限屬性的屬性名(是固定的)

直接上代碼:

  /**
     * 可序列化
     */
    private static final int FLAG_SERIALIZABLE = 1;  
//獲取當(dāng)前登錄人權(quán)限
 Integer secretLevel = getUserSecretLevel();
        if(secretLevel!=null){
            SFunction func = null;
            final MethodHandles.Lookup lookup = MethodHandles.lookup();
            //po的返回Integer的一個方法
            MethodType methodType = MethodType.methodType(Integer.class, entityClass);
            final CallSite site;
            try {
                //方法名叫做:getSecretLevel  轉(zhuǎn)換為 SFunction function interface對象
                site = LambdaMetafactory.altMetafactory(lookup,
                        "invoke",
                        MethodType.methodType(SFunction.class),
                        methodType,
                        lookup.findVirtual(entityClass, "getSecretLevel", MethodType.methodType(Integer.class)),
                        methodType,FLAG_SERIALIZABLE);
                func = (SFunction) site.getTarget().invokeExact();
                //數(shù)據(jù)小于這個級別的都查出來
                queryWrapper.le(func,secretLevel);
            } catch (Throwable e) {
                log.error("獲取getSecretLevel方法錯誤",e);
            }
        }

mybatis-plus QueryWrapper LambdaQueryWrapper

ContractTemplate::getTemplateCode 轉(zhuǎn)為對應(yīng)的字段

LambdaQueryWrapper<SomeClass> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
? ? ? ? objectLambdaQueryWrapper.eq(searchDto.getTemplateCode() != null, ContractTemplate::getTemplateCode, searchDto.getTemplateCode());

? ? ? ? IPage<SomeClass> page = page(MybatisPlusUtil.setPageParams(pageNo, pageSize), objectLambdaQueryWrapper);
? ? ? return page

QueryWrapper

QueryWrapper<SomeClass> queryWrapper = Wrappers.query();
? ? ? ? queryWrapper.eq(searchDto.getTemplateCode() != null, TemplateConst.COL_TEMPLATE_CODE, searchDto.getTemplateCode())
? ? ? ? ? ? ? ? .ge(searchDto.getStartDate() != null, TemplateConst.COL_CREATE_TIME, searchDto.getStartDate())
? ? ? ? ? ? ? ? .lt(searchDto.getEndDate() != null, TemplateConst.COL_CREATE_TIME, DateUtils.addDays(searchDto.getEndDate(), 1))
? ? ? ? ? ? ? ? .eq(searchDto.getContractCategoryId() != null, TemplateConst.COL_CATEGORY_ID, searchDto.getContractCategoryId())
? ? ? ? ? ? ? ? .and(i -> i.like(TemplateConst.COL_TEMPLATE_NAME, searchDto.getKeyword()).or().like(TemplateConst.COL_DESCRIPTION, searchDto.getKeyword()))
? ? ? ? ? ? ? ? .eq(searchDto.getIs_enabled() != null, TemplateConst.COL_IS_ENABLED, searchDto.getIs_enabled())
? ? ? ? ? ? ? ? // 未標志刪除的數(shù)據(jù)
? ? ? ? ? ? ? ? .eq(CommonConst.DBColName.DEL_FLAG, CommonConst.IsEnabled.ENABLED.getCode())
? ? ? ? ? ? ? ? .orderByDesc(TemplateConst.COL_CREATE_TIME)
? ? ? ? ? ? ? ? ;
? ? ? ? IPage<ContractTemplate> page = page(MybatisPlusUtil.setPageParams(pageNo, pageSize), queryWrapper);
? ? ? ? return MybatisPlusUtil.parsePageDTO(page);

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

相關(guān)文章

  • Struts2實現(xiàn)多文件上傳功能

    Struts2實現(xiàn)多文件上傳功能

    這篇文章主要為大家詳細介紹了Struts2實現(xiàn)多文件上傳功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • java遍歷讀取xml文件內(nèi)容

    java遍歷讀取xml文件內(nèi)容

    這篇文章主要為大家介紹了java遍歷讀取xml文件內(nèi)容,感興趣的小伙伴們可以參考一下
    2016-01-01
  • SpringBoot實現(xiàn)自定義Starter的步驟詳解

    SpringBoot實現(xiàn)自定義Starter的步驟詳解

    在SpringBoot中,Starter是一種特殊的依賴,它可以幫助我們快速地集成一些常用的功能,例如數(shù)據(jù)庫連接、消息隊列、Web框架等。在本文中,我們將介紹如何使用Spring Boot實現(xiàn)自定義Starter,需要的朋友可以參考下
    2023-06-06
  • 基于JVM 調(diào)優(yōu)的技巧總結(jié)分析

    基于JVM 調(diào)優(yōu)的技巧總結(jié)分析

    本篇文章是對JVM 調(diào)優(yōu)的技巧進行了總結(jié)和分析。需要的朋友參考下
    2013-05-05
  • 解決springboot 連接 mysql 時報錯 using password: NO的方案

    解決springboot 連接 mysql 時報錯 using password: NO的方案

    在本篇文章里小編給大家整理了關(guān)于解決springboot 連接 mysql 時報錯 using password: NO的方案,有需要的朋友們可以學(xué)習(xí)下。
    2020-01-01
  • java把excel內(nèi)容上傳到mysql實例代碼

    java把excel內(nèi)容上傳到mysql實例代碼

    這篇文章主要介紹了java把excel內(nèi)容上傳到mysql實例代碼,具有一定借鑒價值,需要的朋友可以參考下
    2018-01-01
  • java 非對稱加密算法RSA實現(xiàn)詳解

    java 非對稱加密算法RSA實現(xiàn)詳解

    這篇文章主要介紹了java 非對稱加密算法RSA實現(xiàn)詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • MyBatis獲取參數(shù)值的兩種方式詳解

    MyBatis獲取參數(shù)值的兩種方式詳解

    本文主要介紹了MyBatis獲取參數(shù)值的兩種方式詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Maven?Pom?文件中的隱式依賴導(dǎo)致Jar沖突問題

    Maven?Pom?文件中的隱式依賴導(dǎo)致Jar沖突問題

    這篇文章主要介紹了Maven?Pom?文件中的隱式依賴導(dǎo)致Jar沖突問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • SpringApplicationRunListener監(jiān)聽器源碼詳解

    SpringApplicationRunListener監(jiān)聽器源碼詳解

    這篇文章主要介紹了SpringApplicationRunListener監(jiān)聽器源碼詳解,springboot提供了兩個類SpringApplicationRunListeners、SpringApplicationRunListener(EventPublishingRunListener),spring框架還提供了一個ApplicationListener接口,需要的朋友可以參考下
    2023-11-11

最新評論