SpringMVC:解决406 not acceptable
最近的项目中使用springMVC,在前台页面中报406 not acceptable的错误.
在controller层的代码
@RequestMapping("/item/list")
@ResponseBody
public EUDataGridResult getItemList(Integer page, Integer rows) {
EUDataGridResult result = itemService.getItemList(page, rows);
return result;
}
在controller层的result中能获取到值,但是在前台页面报如下的错:
解决方法:
由于设置了@ResponseBody,要把对象转换成json格式,缺少转换依赖的jar包,需要在pom文件中,添加jar包的引用.jackson-core-2.8.1jar,jackson-databind-2.4.2jar,jackson-annotations-2.4.0-jar
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.0</version>
</dependency>
springmvc的配置文件中是<mvc:annotation-driven />即可.