SpringBoot 학습 14:springboot boot 이상 처리 방식 4(Simple Mapping Exception Resolver 처리 이상 사용)

2898 단어 자바
이상 처리 방법 3 의 전역 이상 처리 컨트롤 러 를 수정 하면 됩 니 다.
package bjsxt.exception;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import java.util.Properties;

/**
 * Created by Administrator on 2019/2/14.
 *        ,  SimpleMappingExceptionResolver        
 *   :                       ,      
 *   :             
 */

@Configuration
public class GlobalException {

    /**
     *
     * @return
     */
    @Bean
    public SimpleMappingExceptionResolver getSimpleMappingExceptionResolver(){
        SimpleMappingExceptionResolver resolver=new SimpleMappingExceptionResolver();
        Properties properties=new Properties();
        /**
         *    :     ,            
         *    :    
         */
        properties.put("java.lang.ArithmeticException","error_arithmetic");
        properties.put("java.lang.NullPointerException","error_nullPointer");
        resolver.setExceptionMappings(properties);
        return resolver;
    }

}

 
다음으로 전송:https://www.cnblogs.com/duanrantao/p/10374008.html

좋은 웹페이지 즐겨찾기