spring 版本:3.2.4 html
跟蹤到spring mvc中查看到的異常:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation java
spring中拋出異常的方法: web
org.springframework.web.servlet.DispatcherServlet.doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception spring
@RequestMapping(value="awardByPage",produces="text/plain;charset=UTF-8") public @ResponseBody JSONResponse awardByPage(@RequestParam int pageIndex) { return JSONResponse.buildSuccess(awardService.awardLogByPage(pageIndex)); }
1. 刪除代碼中的: json
,produces="text/plain;charset=UTF-8"2. 網絡上查找的其它解決方案:
<!-- 啓動JSON格式的配置 --> <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <!--解決 HttpMediaTypeNotAcceptableException: Could not find acceptable representation --> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean>
1. controller中返回的內容沒有get方法, 網絡
解決辦法:添加get方法; mvc
2. 因爲設置了@ResponseBody,要把對象轉換成json格式,缺乏轉換依賴的jar包,故此錯。
解決辦法: 加入依賴的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar問題解決。
app