gaoyu fe8b846ec2 更改pass-cloud框架 | пре 2 година | |
---|---|---|
.. | ||
src | пре 2 година | |
README.md | пре 3 година | |
pom.xml | пре 2 година |
按配置规则,将对象中指定属性的值翻译为显示名称,并在对象上扩展属性并赋值为显示名称。
@Trans(source = "person", parameter = "managers")
public CommonResult<ResponseDepartmentItemVO> queryDepartmentDetail(
@Valid @RequestBody QueryDepartmentDetailDTO queryDepartmentDetailDTO) {
Department department = departmentService.queryDepartmentDetail(queryDepartmentDetailDTO.getId());
ResponseDepartmentItemVO responseDepartmentItemVO = ConvertDepartmentTool.INSTANCE.convert2ResponseItemDTO(department);
return ResultHelper.single(responseDepartmentItemVO);
}
自定义翻译模式使用示例:
翻译器代码
@Slf4j
@Service
public class PersonNameTranslator implements ITranslator {
@Autowired
private IPersonService personService;
@Override
public String trans(String parameter) {
Person person = personService.queryPersonDetail(Long.valueOf(parameter));
return person.getName();
}
@Override
public Map<String, Object> transBatch(List<String> parameter) {
Map<String, Object> resultMap = new HashMap<>(16);
return resultMap;
}
}
Controller代码
@Trans(type = TransType.SERVICE, batch = true, source = "personNameTranslator", parameter = "managers", target = "managerShowName")
public CommonResult<ResponseDepartmentItemVO> queryDepartmentDetail(
@Valid @RequestBody QueryDepartmentDetailDTO queryDepartmentDetailDTO) {
Department department = departmentService.queryDepartmentDetail(queryDepartmentDetailDTO.getId());
ResponseDepartmentItemVO responseDepartmentItemVO = ConvertDepartmentTool.INSTANCE.convert2ResponseItemDTO(department);
return ResultHelper.single(responseDepartmentItemVO);
}
多个翻译器同时使用使用示例:
@Transes({
@Trans(type = TransType.SERVICE, batch = true, source = "personNameTranslator", parameter = "managers", target = "managerShowName"),
@Trans(source = "t_project", parameter = "projectIds", target = "projectsShowName")})
public CommonResult<ResponseDepartmentItemVO> queryDepartmentDetail(
@Valid @RequestBody QueryDepartmentDetailDTO queryDepartmentDetailDTO) {
Department department = departmentService.queryDepartmentDetail(queryDepartmentDetailDTO.getId());
ResponseDepartmentItemVO responseDepartmentItemVO = ConvertDepartmentTool.INSTANCE.convert2ResponseItemDTO(department);
return ResultHelper.single(responseDepartmentItemVO);
}