https://blog.csdn.net/weixin_43836046/article/details/96869635?utm_source=app 讲的最好!
这样用:
@RestController
@RequestMapping("/helloResult")
@ResponseResultBody
public class HelloResultController {
private static final HashMap<String, Object> INFO;
static {
INFO = new HashMap<String, Object>();
INFO.put("name", "galaxy");
INFO.put("age", "70");
}
@GetMapping("hello")
public HashMap<String, Object> hello() {
return INFO;
}
/** 测试重复包裹 */
@GetMapping("result")
public Result<Map<String, Object>> helloResult() {
return Result.success(INFO);
}
@GetMapping("helloError")
public HashMap<String, Object> helloError() throws Exception {
throw new Exception("helloError");
}
@GetMapping("helloMyError")
public HashMap<String, Object> helloMyError() throws Exception {
throw new ResultException();
}
}