🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、概述 有时候,在一个场景里面,会用到多种字典翻译,有列表,有对象,还有封装对象等,不能用简单的列表字典或实体字典翻译来实现了; 这个时候,引入组合字段翻译方案; ## 二、方案 基于以上的列表(分页列表、普通列表)和单个实体翻译,组合来解决即可; >[danger] > 1、只要正确设定翻译的对象路径,字段名称,及方法,平台会自动帮你归类翻译类型和字段,非常方便; ## 三、实例 最复杂的情况,如业务中,包含tab页,通过tab切换,调用不同的代码,但是在同一个controller方法中,那么,现在的平台,也能完美支持了,例如: ``` @GetMapping("/api/business/card/cardinfo/view") @RayDynamicConvertFieldOfEntityGroupInSingleEntity({ @RayDynamicConvertFieldOfEntityInSingleEntity(entityPath = "cardInfo", fieldName = "cardSource", refEntityName = "CardSource", refEntitySourceFieldName = "sourceId", refEntityTargetFieldName = "sourceName"), // @RayDynamicConvertFieldOfEntityInSingleEntity(entityPath = "cardInfo", fieldName = "cardUserStaff", refEntityName = "SysStaff", refEntitySourceFieldName = "staffId", refEntityTargetFieldName = "staffCode"), // @RayDynamicConvertFieldOfEntityInSingleEntity(entityPath = "cardInfo", fieldName = "topAgentStaff", refEntityName = "SysStaff", refEntitySourceFieldName = "staffId", refEntityTargetFieldName = "staffName"), // @RayDynamicConvertFieldOfEntityInSingleEntity(entityPath = "cardInfo", fieldName = "terminalAgentStaff", refEntityName = "SysStaff", refEntitySourceFieldName = "staffId", refEntityTargetFieldName = "staffName") // }) @RayDynamicConvertFieldOfStaticDictClassGroupInSingleEntity({ // @RayDynamicConvertFieldOfStaticDictClassInSingleEntity(entityPath = "cardInfo", fieldName = "cardStatus", refStaticDictClazz = "com.ray.iot.constants.CardStatus"), // @RayDynamicConvertFieldOfStaticDictClassInSingleEntity(entityPath = "cardInfo", fieldName = "realNameStatus", refStaticDictClazz = "com.ray.iot.constants.CardRealNameStatus")// }) @RayDynamicConvertFieldOfStaticDictClassGroupInPageEntity({ // @RayDynamicConvertFieldOfStaticDictClassInPageEntity(fieldName = "orderStatus", refStaticDictClazz = "com.ray.iot.constants.CardOrderStatus"), // @RayDynamicConvertFieldOfStaticDictClassInPageEntity(fieldName = "orderType", refStaticDictClazz = "com.ray.iot.constants.CardOrderType"), // @RayDynamicConvertFieldOfStaticDictClassInPageEntity(fieldName = "isOrderCanceled", refStaticDictClazz = "org.wbase.framework.core.staticdict.YesOrNo"), // @RayDynamicConvertFieldOfStaticDictClassInPageEntity(fieldName = "currentCardStatus", refStaticDictClazz = "com.ray.iot.constants.CardStatus"), // @RayDynamicConvertFieldOfStaticDictClassInPageEntity(fieldName = "requestCardStatus", refStaticDictClazz = "com.ray.iot.constants.CardStatus") // }) @RayDynamicConvertFieldOfEntityGroupInPageEntity({ // @RayDynamicConvertFieldOfEntityInPageEntity(fieldName = "agentStaffId", refEntityName = "SysStaff", refEntitySourceFieldName = "staffId", refEntityTargetFieldName = "staffCode") // }) public ResponseEntity<ResponseObject> view(@RequestHeader String rayAccessToken, @RequestParam long cardId, @RequestParam(required = true) long tabIndex, @RequestParam int curPage, @RequestParam int pageSize, @RequestParam(required = false) String orderFieldName, @RequestParam(required = false) String orderDirection) throws Exception { return ResponseEntity.ok(cardInfoService.view(cardId, tabIndex, curPage, pageSize, orderFieldName, orderDirection)); } ``` service中的代码,包括复用了pageobject; ``` @RayServiceMethod public ResponseObject view(long cardId, long tabIndex, int curPage, int pageSize, String orderFieldName, String orderDirection) throws Exception { CardInfo cardInfo = cardInfoDao.findById(cardId).get(); model.setCardInfo(cardInfo); model.addStaticDict(CardStatus.class, cardInfo.getCardStatus()); if (tabIndex == 1) { model.setPageobject(cardOrderPackageHistoryDao.findByCardId(cardId, PagableBuilder.getPageable(curPage, pageSize, orderFieldName, orderDirection))); } if (tabIndex == 2) { model.setPageobject(cardStatusRequestHistoryDao.findByCardId(cardId, PagableBuilder.getPageable(curPage, pageSize, orderFieldName, orderDirection))); } if (tabIndex == 3) { model.setPageobject(cardPooledMonthlyUsageDao.findByCardId(cardId, PagableBuilder.getPageable(curPage, pageSize, orderFieldName, orderDirection))); } if (tabIndex == 4) { model.setPageobject(cardAgentProfitSettledDao.findByCardId(cardId, PagableBuilder.getPageable(curPage, pageSize, orderFieldName, orderDirection))); } if (tabIndex == 5) { model.setPageobject(cardAgentProfitDao.findByCardId(cardId, PagableBuilder.getPageable(curPage, pageSize, orderFieldName, orderDirection))); } return responseObj; } ```