1. @ControllerAdvice
    2. public class GlobalExceptionHandler {
    3. @ResponseBody
    4. @ExceptionHandler(Exception.class)
    5. public Object handleException(Exception e) {
    6. String msg = e.getMessage();
    7. if (msg == null || msg.equals("")) {
    8. msg = "服务器出错";
    9. }
    10. JSONObject jsonObject = new JSONObject();
    11. jsonObject.put("message", msg);
    12. return jsonObject;
    13. }
    14. }