springboot 异常捕获

package com.fuwo.headline.common.exception;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;

import java.io.IOException;


@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(SystemException.class)
    public ResponseEntity handleDataNotFoundException(SystemException ex, WebRequest request) throws IOException {
        return new ResponseEntity(
                "ok", new HttpHeaders(), HttpStatus.OK);
    }

}
 
  
 
  
 
  
 
  

                            
                        
                    
                    
                    

你可能感兴趣的:(springboot)