控制层代码如下: //取到的哪个页面 @RequestMapping("/dept.page") public ModelAndView page(){ return new ModelAndView("dept"); } //新增部门的方法 @RequestMapping("/save.json") @ResponseBody public JsonData saveDept(DeptParam param){ sysDeptService.save(param); return JsonData.success(); } //1 @RequestMapping("/Tree.json") @ResponseBody public JsonData tree(){ List<DeptLevelDto> dtoList = sysTreeService.deptTree(); return JsonData.success(dtoList); } 请求处理拦截:如下 public class SpringExceptionResolver implements HandlerExceptionResolver { public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception ex) { String url = request.getRequestURI().toString(); ModelAndView mv ; String defaultMsg = "System error"; //这里我们要求项目中的所有请求json数据,都使用json结尾 if(url.endsWith(".json")){ if(ex instanceof SmallException || ex instanceof ParamException){ JsonData result = JsonData.fail(ex.getMessage()); mv = new ModelAndView("jsonView",result.toMap()); }else { System.out.print(ex); JsonData result = JsonData.fail(defaultMsg); mv = new ModelAndView("jsonView",result.toMap()); } //我们要求项目中所有请求page页面,都是用.page结尾 }else if(url.endsWith(".page")){ //log.error("unknow page exception,url"+ url,ex); JsonData result = JsonData.fail(defaultMsg); mv = new ModelAndView("exception",result.toMap()); }else { //log.error("unknow exception,url"+ url,ex); JsonData result = JsonData.fail(defaultMsg); mv = new ModelAndView("jsonView",result.toMap()); } return mv; } } 业务层代码:如下: @Resource private SysDeptMapper sysDeptMapper; //新增 public void save(DeptParam param){ BeanValidator.check(param); if(checkExist(param.getParentId(),param.getName(),param.getId())){ throw new ParamException("同一层级下存在相同的部门"); } SysDept dept = SysDept.builder().name(param.getName()).parentId(param.getParentId()) .seq(param.getSeq()).remark(param.getRemark()).build(); dept.setLevel(LevelUtil.calculatelevel(getLevel(param.getParentId()),param.getParentId())); dept.setOperator("System");//TODO dept.setOperateIp("127.0.0.1");//TODO dept.setOperateTime(new Date()); sysDeptMapper.insertSelective(dept); } 错误提示:如下 url:{} , param:{}/sys/dept/dept.page{}五月 09, 2018 8:38:40 下午 org.springframework.web.servlet.PageNotFound noHandlerFound警告: No mapping found for HTTP request with URI [/sys/dept/tree.json] in DispatcherServlet with name 'spring'五月 09, 2018 8:38:40 下午 org.springframework.web.servlet.PageNotFound noHandlerFound警告: No mapping found for HTTP request with URI [/favicon.ico] in DispatcherServlet with name 'spring'url:{} , param:{}/sys/dept/save.json{"parentId":["0"],"id":[""],"name":["shiye"],"seq":["1"], "remark":["gds"]}org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError 以上是新增部门信息,报的错误,数据库测试链接成功
cxxyjsj
相关分类