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

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

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

LambdaQueryWrapper動(dòng)態(tài)加過(guò)濾條件 動(dòng)態(tài)Lambda

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

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的一個(gè)方法
            MethodType methodType = MethodType.methodType(Integer.class, entityClass);
            final CallSite site;
            try {
                //方法名叫做:getSecretLevel  轉(zhuǎn)換為 SFunction function interface對(duì)象
                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ù)小于這個(gè)級(jí)別的都查出來(lái)
                queryWrapper.le(func,secretLevel);
            } catch (Throwable e) {
                log.error("獲取getSecretLevel方法錯(cuò)誤",e);
            }
        }

mybatis-plus QueryWrapper LambdaQueryWrapper

ContractTemplate::getTemplateCode 轉(zhuǎn)為對(duì)應(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())
? ? ? ? ? ? ? ? // 未標(biāo)志刪除的數(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);

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

相關(guān)文章

最新評(píng)論