`
wststar
  • 浏览: 16968 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Spring MVC 的json问题(406 Not Acceptable)

阅读更多

Controller中方法如下:

 

 @RequestMapping("/flexgrid")
    @ResponseBody
    public Flexgrid flexgrid(BaseBook baseBook) {
	return baseBookService.flexgrid(baseBook);
    }

然后需要将返回的数据做json处理,在这里我们调用第三方的包jackson。

需要导入jackson-mapper-asl-1.9.10.jar和jackson-core-asl-1.9.10.jar。
然后在自己的Spring配置文件中进行下数据格式的配置:

<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
	<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
				<value>text/html;charset=UTF-8</value>
			</list>
		</property>
	</bean>

	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
			</list>
		</property>
	</bean>

 之所以有的网友会报406错误,是因为没有对返回的数据做Json处理。

Spring的标签只是声明返回的是一个实体对象,需要自己去转换成json.

 

 

分享到:
评论

相关推荐

    Whether mandatory donation is acceptable or not?

    Whether mandatory donation is acceptable or not?

    jackson-core-asl-1.9.13及jackson-mapper-asl-1.9.13架包.rar

    可用于Spring MVC框架,spring MVC中返回使用@ResponseBody注解返回时,后台没报错,就控制台显示406 Not Acceptable 原因是缺少jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar

    elasticsearch-head

    ## Synopsis ... ## Motivation This was created because ElasticSearch 5 removed the ability to run ElasticSearch Head as an Elastic Plugin. This offers an alternative to self-hosting in your own web ...

    jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar

    spring MVC中返回使用@ResponseBody注解返回时,后台没报错,就控制台显示406 Not Acceptable 原因是缺少jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar

    Resizes Images to sizes acceptable by half life for transiti

    Resizes Images to sizes acceptable by half life for transitioning into pldecal.wad files This code is incomplete... A Majority of the programming has been accomplished.

    JSP页面报错列表查询

    406 Not Acceptable 指定的资源已经找到,但它的MIME类型和客户在Accpet头中所指定的不兼容(HTTP 1.1新)。 407 Proxy Authentication Required 类似于401,表示客户必须先经过代理服务器的授权。(HTTP 1.1新) ...

    ANSI-ASHRAE Standard 62.1-2019 Ventilation for Acceptable Indoor

    ANSI-ASHRAE Standard 62.1-2019 Ventilation for Acceptable Indoor

    json-api:与框架无关的JSON API(jsonapi.org)实现

    例如,它有助于正确地使用Unsupported Media Type (HTTP代码415)和Not Acceptable Unsupported Media Type (HTTP代码406)对无效请求做出响应。 您无需在每个请求上手动验证所有输入参数。 您可以配置服务支持...

    node-contrib-mvcgenerator:一种基于简单的JSON配置来搭建MVC项目的工具

    node-contrib-mvcgenerator一种基于简单的JSON配置来搭建MVC项目的工具。 注意:此项目无需维护-此处存在更好的替代方法: : 配置文件示例: exports . config = { // filename extensions - acceptable formats: js...

    Crawler.zip

    一个简单的网络爬虫资源包,是之前在发现的,文件包好像还挺完整,本来应该免积分的,但是因为急需积分,所以设置为两积分,有兴趣的可以下载试试

    play-content-negotiation:Play框架的声明式内容协商

    不幸的是,这种方法存在问题:如果服务器需要返回406 Not Acceptable HTTP响应,则Play框架无法在响应中提供受支持的内容类型的列表,这对于开发人员编程客户端非常有帮助。用于您的Web应用程序。 play-content-...

    rack-accepts:[UNMAINTAINED] 机架中间件拒绝蹩脚的 http 接受标头

    机架中间件拒绝蹩脚的 http 接受标头当请求不支持的类型时返回“406 Not Acceptable”状态。导轨用法 config.middleware.use Rack::Accepts执照版权所有 (c) 2010 Andrew Nesbitt 特此授予任何人免费获得本软件副本...

    SIP - Understanding the Session Initiation Protocol, 2nd Ed - 1459

    5.4.7 406 Not Acceptable 115 5.4.8 407 Proxy Authentication Required 115 5.4.9 408 Request Timeout 116 5.4.10 409 Conflict 116 5.4.11 410 Gone 116 5.4.12 411 Length Required 116 5.4.13 413 Request ...

    sip RFC3261 中文版

    21.4.7 406 Not Acceptable 209 21.4.8 407 Proxy Authentication Required 209 21.4.9 408 Request Timeout 210 21.4.10 410 Gone 210 21.4.11 413请求实体过大。 210 21.4.12 414 Request-URI Too Long 210 21.4....

    How to implement SCP-ECG, Part II

    It is not anymore acceptable that, in the age of information technology, millions of Euros are wasted for unnecessarily repeated tests or that patients do not obtain appropriate care because relevant ...

    HowToImplement SCP-ECG_Part I

    It is not anymore acceptable that, in the age of information technology, millions of Euros are wasted for unnecessarily repeated tests or that patients do not obtain appropriate care because relevant ...

    LaTeX模板llncs

    部分国内外会议的LaTeX模板Lecture Notes in Computer Science (LNCS) ...Each contribution must be accompanied by a Springer copyright form, a so-called 'Consent to ... Modified forms are not acceptable.

    svm数据挖掘挖掘挖掘挖掘挖掘挖掘挖掘

    acceptable results. Although users do not need to understand the underlying theory behind SVM, we brie y introduce the basics necessary for explaining our procedure. A classi cation task usually ...

    node-crawler.zip

    msg: "Not Acceptable" } 就是 没有想要的值 现在就说对 x-sign 的的地方 通过node进行js的处理 进行数据的调用可以返回数为 返回结果为 ———————————————— 版权声明:本文为CSDN博主「我来了007...

    Why optical lithography will live forever

    Not only must the process resolve the minimum feature size but overlay errors must be held to tight tolerances, exquisitely complex patterns must be printed with high yield, and the overall cost of ...

Global site tag (gtag.js) - Google Analytics