SpringBoot注釈を使用したグローバルキャプチャ例外

1284 ワード

/**
 * Springboot     
 */

@RestControllerAdvice(basePackages = "com.example.demo.controller")//  
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)//     
    @ResponseBody
public Map error(){
    HashMap map = new HashMap<>();
    map.put("errorCode","500");
    map.put("errorMsg","    ");
    return  map;
}
}

 
転載先:https://www.cnblogs.com/smiledGo/p/10853178.html