@PostMapping("/v1/straddle") public Result<String> paging(@RequestBody @Valid final SealPagingDTO sealPagingDTO, final BindingResult bindingResult) { if (log.isInfoEnabled()) { log.info("开始调用骑缝章服务.applyNo:[{}],param:[{}]", sealPagingDTO.getApplyNo(), sealPagingDTO); } if (bindingResult.hasErrors()) { return Result.failure(bindingResult.getAllErrors() .get(0) .getDefaultMessage()); } // 开启耗时统计. final StopWatch sw = new StopWatch(); sw.start(); // 骑缝章. final SealResultDTO<SealPagingResultDTO> resultDTO = this.sealPagingService.sealPaging(sealPagingDTO); sw.stop(); if (log.isInfoEnabled()) { log.info("调用签章骑缝章服务调用结束.applyNo:[{}],result:[{}],耗时为:[{}]毫秒", sealPagingDTO.getApplyNo(), resultDTO, sw.getTotalTimeMillis()); } return Optional.of(resultDTO) .filter(res -> SealConstant.HTTP_SUCCESS_CODE.equals(res.getRespCode())) .map(res -> Result.success(res.getDatas())) .orElseGet(() -> Result.failure(resultDTO.getRespMsg())); } 第一return返回的是String类型,第二个return成功返回的是T类型,怎么修改Result<String>
时间: 2024-02-14 16:26:40 浏览: 85
精细金属掩模板(FMM)行业研究报告 显示技术核心部件FMM材料产业分析与市场应用
要修改第一个返回类型为String的问题,可以将方法的返回类型改为Result<String>,并在return语句中使用Result.success()方法来封装返回结果。具体修改如下:
```java
@PostMapping("/v1/straddle")
public Result<String> paging(@RequestBody @Valid final SealPagingDTO sealPagingDTO,
final BindingResult bindingResult) {
if (log.isInfoEnabled()) {
log.info("开始调用骑缝章服务.applyNo:[{}],param:[{}]", sealPagingDTO.getApplyNo(), sealPagingDTO);
}
if (bindingResult.hasErrors()) {
return Result.failure(bindingResult.getAllErrors()
.get(0)
.getDefaultMessage());
}
// 开启耗时统计.
final StopWatch sw = new StopWatch();
sw.start();
// 骑缝章.
final SealResultDTO<SealPagingResultDTO> resultDTO = this.sealPagingService.sealPaging(sealPagingDTO);
sw.stop();
if (log.isInfoEnabled()) {
log.info("调用签章骑缝章服务调用结束.applyNo:[{}],result:[{}],耗时为:[{}]毫秒",
sealPagingDTO.getApplyNo(),
resultDTO,
sw.getTotalTimeMillis());
}
return Optional.of(resultDTO)
.filter(res -> SealConstant.HTTP_SUCCESS_CODE.equals(res.getRespCode()))
.map(res -> Result.success(res.getDatas()))
.orElseGet(() -> Result.failure(resultDTO.getRespMsg()));
}
```
这样就将第一个return语句的返回类型修改为Result<String>了。
阅读全文