企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 一、概述 有时候同一个实体,在不同业务中,需要选择性的屏蔽字段; ## 二、解决方案 在controller中,加上配置; ``` @GetMapping("/api/system/log/list") @RayDynamicFilterFieldsInPageEntityGroup({ // @RayDynamicFilterFieldsInPageEntity(excludeFields = "operateTime,operateEndTime,operateStartTime")// }) public ResponseEntity<ResponseObject> list(@RequestHeader String rayAccessToken, @RequestParam(required = false) List<String> dateTimeScope, @RequestParam(required = false) String infoCode, @RequestParam(required = false) String operateContent, @RequestParam int curPage, @RequestParam int pageSize, @RequestParam(required = false) String orderFieldName, @RequestParam(required = false) String orderDirection) throws Exception { return ResponseEntity.ok(sysLogService.list(dateTimeScope, infoCode, operateContent, curPage, pageSize, orderFieldName, orderDirection)); } ``` 这样就把列表每个实体的已配置字段过滤掉不显示; ## 三、完整方案 可以支持分页、普通列表以及单个实体的过滤,支持多重组合等; 分页: ``` @RayDynamicFilterFieldsInPageEntityGroup @RayDynamicFilterFieldsInPageEntity ``` 普通列表: ``` @RayDynamicFilterFieldsInListEntityGroup @RayDynamicFilterFieldsInListEntity ``` 单个实体: ``` @RayDynamicFilterFieldsInSingleEntityGroup @RayDynamicFilterFieldsInSingleEntity ``` ## 四、实例 ``` @PostMapping(RayOauthServerConstants.rayOauthApiUrlPrefix + apiRequestSimpleUrl) @RayDynamicFilterFieldsInSingleEntityGroup({ // @RayDynamicFilterFieldsInSingleEntity(entityPath = "cardInfo", excludeFields = "cardSource,controlType,pollType,functionType,groupTag,cardUserStaff,topAgentStaff,terminalAgentStaff,version") // }) public ResponseEntity<ResponseObject> view(@RequestHeader String rayOauthServerAppId, @RequestHeader String rayOauthServerTimeStamp, @RequestHeader String rayOauthServerSignature, @RequestParam String userCode) throws Exception { return ResponseEntity.ok(queryCardSynService.response(getOauthClient(), getOauthApiRequest(), userCode)); } public static class QueryCardModel extends RayModel { private Object cardInfo; public Object getCardInfo() { return cardInfo; } public void setCardInfo(Object cardInfo) { this.cardInfo = cardInfo; } } ``` ## 五、特别注意 由于动态删除字段会导致丢失类型,列表和分页的模式,由于是往list里面存放Object数据,所以没有影响;但是,单个实体的时候,必须要用Object来保存对象,不可用指定实体类型,否则会导致无法往指定对象中设置动态生成的丢失类型的对象; 参考代码: ``` public static class QueryFlowModel extends RayModel { private Object cardPooledLatestData; public Object getCardPooledLatestData() { return cardPooledLatestData; } public void setCardPooledLatestData(Object cardPooledLatestData) { this.cardPooledLatestData = cardPooledLatestData; } } ```