提交 8de9aab4 编写于 作者: Y yingjun

修复GlobalExceptionResolver的bug

上级 fe0c3269
package com.yingjun.ssm.dao; package com.yingjun.ssm.dao;
import java.util.List; import com.yingjun.ssm.entity.Goods;
import java.util.Map;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.Cacheable;
import com.yingjun.ssm.entity.Goods; import java.util.List;
import java.util.Map;
public interface GoodsDao { public interface GoodsDao {
/** /**
......
package com.yingjun.ssm.exception; package com.yingjun.ssm.exception;
import java.io.PrintWriter; import com.alibaba.fastjson.JSON;
import com.yingjun.ssm.dto.BaseResult;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;
import com.alibaba.fastjson.JSON; import javax.servlet.http.HttpServletRequest;
import com.yingjun.ssm.dto.BaseResult; import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
/** /**
* 错误信息统一处理 * 错误信息统一处理
...@@ -29,7 +26,7 @@ public class GlobalExceptionResolver implements HandlerExceptionResolver { ...@@ -29,7 +26,7 @@ public class GlobalExceptionResolver implements HandlerExceptionResolver {
@ResponseBody @ResponseBody
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
LOG.error("用户 " + WebUtils.getCookie(request, "userPhone").getValue() + " 访问" + request.getRequestURI() + " 发生错误, 错误信息:" + ex.getMessage()); LOG.error("访问" + request.getRequestURI() + " 发生错误, 错误信息:" + ex.getMessage());
//这里有2种选择 //这里有2种选择
//跳转到定制化的错误页面 //跳转到定制化的错误页面
/*ModelAndView error = new ModelAndView("error"); /*ModelAndView error = new ModelAndView("error");
......
package com.yingjun.ssm.service.impl; package com.yingjun.ssm.service.impl;
import java.util.List; import com.yingjun.ssm.cache.RedisCache;
import com.yingjun.ssm.dao.UserDao;
import com.yingjun.ssm.entity.User;
import com.yingjun.ssm.service.UserService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.yingjun.ssm.cache.RedisCache; import java.util.List;
import com.yingjun.ssm.dao.UserDao;
import com.yingjun.ssm.entity.Goods;
import com.yingjun.ssm.entity.User;
import com.yingjun.ssm.service.UserService;
@Service @Service
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
......
...@@ -3,14 +3,12 @@ package com.yingjun.ssm.util; ...@@ -3,14 +3,12 @@ package com.yingjun.ssm.util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.dyuproject.protostuff.LinkedBuffer; import com.dyuproject.protostuff.LinkedBuffer;
import com.dyuproject.protostuff.ProtostuffIOUtil; import com.dyuproject.protostuff.ProtostuffIOUtil;
import com.dyuproject.protostuff.Schema; import com.dyuproject.protostuff.Schema;
import com.dyuproject.protostuff.runtime.RuntimeSchema; import com.dyuproject.protostuff.runtime.RuntimeSchema;
import com.yingjun.ssm.entity.User;
/** /**
* 序列话工具 * 序列话工具
......
package com.yingjun.ssm.web; package com.yingjun.ssm.web;
import java.util.List; import com.yingjun.ssm.entity.User;
import com.yingjun.ssm.service.UserService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -10,8 +10,7 @@ import org.springframework.ui.Model; ...@@ -10,8 +10,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import com.yingjun.ssm.entity.User; import java.util.List;
import com.yingjun.ssm.service.UserService;
@Controller @Controller
@RequestMapping("/user") @RequestMapping("/user")
......
package com.yingjun.ssm.dao; package com.yingjun.ssm.dao;
import java.util.HashMap; import com.yingjun.ssm.entity.Goods;
import java.util.List;
import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.yingjun.ssm.entity.Goods; import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/spring-dao.xml") @ContextConfiguration("classpath:spring/spring-dao.xml")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册