?控制層代碼如下:
?//取到的哪個(gè)頁面
????@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);
????}
???請(qǐng)求處理攔截:如下
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";
????????//這里我們要求項(xiàng)目中的所有請(qǐng)求json數(shù)據(jù),都使用json結(jié)尾
????????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());
????????????}
????????????//我們要求項(xiàng)目中所有請(qǐng)求page頁面,都是用.page結(jié)尾
????????}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;
????}
}
業(yè)務(wù)層代碼:如下:
@Resource
private?SysDeptMapper?sysDeptMapper;
//新增
public?void?save(DeptParam?param){
????BeanValidator.check(param);
????if(checkExist(param.getParentId(),param.getName(),param.getId())){
????????throw?new?ParamException("同一層級(jí)下存在相同的部門");
????}
????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);
}
錯(cuò)誤提示:如下
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
????
????
????
????以上是新增部門信息,報(bào)的錯(cuò)誤,數(shù)據(jù)庫測(cè)試鏈接成功
1 回答

cxxyjsj
TA貢獻(xiàn)119條經(jīng)驗(yàn) 獲得超22個(gè)贊
異常日志里面寫的很清楚找不到tree.json,? 貼出來的代碼中RequestMapping是Tree.json, 大小寫不一致
添加回答
舉報(bào)
0/150
提交
取消