我有以下控制器:
@Controller
@RequestMapping(path = "/foo/bar")
public classMyController
@PostMapping(path = "/acction")
@ResponseStatus(value = HttpStatus.OK)
public String doAction(@RequestBody final MyDto request) {
try {
someService.resetPassword(request.getSomeData());
return "Success";
} catch (MyException e) {
return String.format("redirect:google.com");
}
}
行return "Success";
看起来很多余。有办法避免吗?
答案 0 :(得分:0)
将返回类型更改为ResponseEntity类,并设置响应状态代码代替字符串“ success”。
@GetMapping("/hello")
ResponseEntity<String> hello() {
return new ResponseEntity<>("Hello World!", HttpStatus.OK);
}