zoukankan      html  css  js  c++  java
  • 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 />即可.



  • 相关阅读:
    Redis
    Linux 命令
    Linux 命令
    Networking
    Networking
    MySQL(5.6) 函数
    MySQL 中事务、事务隔离级别详解
    程序人生:搜索引擎被禁用,你还会写代码吗?
    程序人生:搜索引擎被禁用,你还会写代码吗?
    程序员幽默:老板让明天带条鱼来大家观察
  • 原文地址:https://www.cnblogs.com/chenxiaochan/p/7253408.html
Copyright © 2011-2022 走看看