springboot global catch the exception

Not try catch a runtime exception will be the following code capture

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class EEcontroller {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String,String> errorInfo(){
        Map<String,String> map=new HashMap<>();
        map.put("code","500");
        return  map;
    }
}

 

Guess you like

Origin www.cnblogs.com/hhxylm/p/11118408.html