红框里面的方法转化成JSON格式数据是出现异常17:29:57.737 [http-bio-8080-exec-23] DEBUG o.s.w.s.m.a.AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [com.mvc.action.StudentAction@2aa89e44]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation17:29:57.737 [http-bio-8080-exec-23] DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [com.mvc.action.StudentAction@2aa89e44]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation17:29:57.737 [http-bio-8080-exec-23] DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [com.mvc.action.StudentAction@2aa89e44]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation17:29:57.737 [http-bio-8080-exec-23] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling17:29:57.737 [http-bio-8080-exec-23] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
在网上也找了但是没有解决。
包也有,xml文件也配置了
springMVC提供的异常处理主要有以下几种方式。
几种处理方式为:
1、是直接实现自己的HandlerExceptionResolver。HandlerExceptionResolver是一个接口,springMVC本身已经对其有了一个自身的实现——DefaultExceptionResolver,该解析器只是对其中的一些比较典型的异常进行了拦截处理;
2、是使用注解的方式实现一个专门用于处理异常的Controller——ExceptionHandler。
3、是使用邻接矩阵存放图,邻接矩阵中位于行和列上面点的顺序可以自己定义;
4、是把图中点的名称按照点在邻接矩阵中行或者列上的顺序存放一个数组中;
5、是使用一个数组来标记各个点是否被访问过,数组的大小为图中点的数量;
这个包加上也不行
应该不需要帮助类吧,要不然这个@ResponseBody注解就没有作用了
追答@RequestMapping(value = "/admin/rolesList", method = RequestMethod.GET)
public @ResponseBody
Object rolesList(HttpServletRequest request, HttpServletResponse response, ModelMap model,
RedirectAttributes redirectAttributes, @RequestParam(required = false) String rolesName,
@RequestParam(required = false) String targetType, @RequestParam(required = false) String identityType) {
List recordList = roleManager.findRoles(rolesName, targetType, identityType);
String jsonString = JsonUtil.beanListToJson(recordList); //使用JsonUtil帮助类转换,可以在网上找到很帮助类
return JsonUtil.ajaxJson(response, jsonString);
}
提供下思路给你吧,仔细看报错的log
一条一条看,别说全英文看不懂,一开始大家都这样,耐下心来,不一定全部理解,只要明白是啥意思,比方说这个:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation找不到可以匹配(接受)的数据,你仔细看你写的代码吧,哪个地方配置漏掉什么了吧
Could not find acceptable representation就这一处错误,关键是其他地方没问题。。。。
追答最笨的方法debug,一点点的改,一点点的尝试,这个痛苦的过程就是你成长的过程
本回答被网友采纳