SpringBoot的ProblemDetails-2.ProblemDetails

时间:2024-05-06 07:09:19

接下来我们就使用ProblemDetails处理异常,请求方式异常也属于 ProblemDetails处理的异常,我们就模拟改异常的发生。

ProblemDetails默认是不开启的,要想开启需要进行如下配置:

spring.mvc.problemdetails.enabled=true
package spring.springlogback.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@SuppressWarnings("all")
public class ProblemDetailsController {
    @GetMapping("/t1")
    @ResponseBody
    public String t1(){
        return "hello";
    }
}

 POST方式访问该方法: