异常处理

public class MyExceptionHandler implements HandlerExceptionResolver {
    
	private final Log LOGGER =  LogFactory.getLog(this.getClass());
	
	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
		LOGGER.error("内部系统未处理异常", ex);
		
		ResultVO result = new ResultVO();
		MappingJackson2JsonView view = new MappingJackson2JsonView();
		Map map = new HashMap();
        if (ex instanceof MaxUploadSizeExceededException){
        	map.put("code", CommonErrorCode.PICTURE_UPLOAD_FAIL);
    		map.put("msg", "文件太大");
        } else{
        	map.put("code", -1);
    		map.put("msg", "数据异常");
        }	
        
	    view.setAttributesMap(map);
	    ModelAndView mav = new ModelAndView();
	    mav.setView(view);
        return mav;
	}
	
}

 

转载于:https://my.oschina.net/xl76832215/blog/684592

你可能感兴趣的:(异常处理)