1.解决SpringMVC注解返回参数 (406 not acceptable)的错误
可能出现问题的地方#
注:我的问题出现在没有jar包,以及jar包版本
-
springMvc配置文件的开头,需要有:版本是3.0以上的
1 2
xmlns:mvc="http://www.springframework.org/schema/mvc" http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
-
SpringMVC 配置文件中要有
1 2
<!-- 注解驱动--> <mvc:annotation-driven />
-
要有Json解析的jar包,不同版本需要的不一样,tomcat注意清空服务器上的缓存。
我的springMVC是4.1.3的
org.springframework spring-webmvc 4.1.3.RELEASE
我的JSON依赖包
1 2 3 4 5 6 7 8 9 10 11
<!-- JSON --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.1.1</version> </dependency>
-
-
要在方法上面加上
@ResponseBody
注解1 2 3 4 5 6 7 8 9
@RequestMapping("/transmissionParam/receiveParamByGetOrPost") @ResponseBody public ReturnMessage receiveParamByGetOrPost(String userId) { ReturnMessage retMsg = new ReturnMessage(); logger.info("接收成功!"); retMsg.setSuccess(true); retMsg.setData(userId); return retMsg; }
参考链接: