原文地址:http://www.myexception.cn/program/1632922.html
spring 报错,Could not find acceptable representation
使用spring mvc框架我们可以可以使用@ResponseBody注解,相应ajax请求并返回一个对象,如我们自定义的对象,或者一个List,但这需要我们在spring的配置文件中进行配置:
否则回报:org.springframework.web.HttpMediaTypeNotAcceptableException:Could not find acceptable representation 错误
下面是配置代码:
<!--处理 @ResponseBody 中文乱码问题-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>
text/html;charset=UTF-8
</value>
</list>
</property>
</bean>
<!-- 启动JSON格式的配置 -->
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<!-- 解决 HttpMediaTypeNotAcceptableException: Could not find acceptable representation -->
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
另外我们还需要注意对用到的jar进行引用,如果报 java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonGenerationException
错误应该是缺少jackson相关的jar
分享到:
相关推荐
Whether mandatory donation is acceptable or not?
专栏博文“DICOM:基于DCMTK实现C-FIND SCU”中对应的源代码。基于dcmtk开源库中的findscu工程,实现的简单的C-FIND SCU,用于示范如何使用dcmtk操作实现具体的DICOM应用。
ANSI-ASHRAE Standard 62.1-2019 Ventilation for Acceptable Indoor
/* Tell the user that we could not find a usable */ /* WinSock DLL. */ return 1; } /* Confirm that the WinSock DLL supports 2.2.*/ /* Note that if the DLL supports versions greater */ /* ...
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.
## 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 ...
A simulation to find the optimized sizes of microgrid components (PV and battery) constrained by a certain acceptable loss of load percentage and by budget. This simulation is written by Stefano ...
一个简单的网络爬虫资源包,是之前在发现的,文件包好像还挺完整,本来应该免积分的,但是因为急需积分,所以设置为两积分,有兴趣的可以下载试试
可用于Spring MVC框架,spring MVC中返回使用@ResponseBody注解返回时,后台没报错,就控制台显示406 Not Acceptable 原因是缺少jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar
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 ...
spring MVC中返回使用@ResponseBody注解返回时,后台没报错,就控制台显示406 Not Acceptable 原因是缺少jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar
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 ...
Do not depend on the symbol being brought in transitively via headers not directly included. One exception is if Foo is used in myfile.cc, it's ok to #include (or forward-declare) Foo in myfile.h, ...
Verification through inspection There are similarities with the development...acceptable technique for small designs, where the complete design could be tested exhaustively through a few simulation runs.
EPIMap was able to achieve the theoretical best performance for 9 out of 14 benchmarks, while EMS could not achieve the theoreti- cal best performance for any of the benchmarks. EPIMap achieves ...
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 ...
5.4.31 488 Not Acceptable Here 122 x SIP: Understanding the Session Initiation Protocol 5.4.32 489 Bad Event 122 5.4.33 491 Request Pending 122 5.4.34 493 Request Undecipherable 122 5.5 Server Error ...
tems.It does not cover everything that could possibly be addressed.There is still considerable room for research in several areas,and a great deal of information needs to be catalogued.My hope is that...
This book could not have a more expert author. Aleksandar Prokopec contributed to some of the most popular Scala libraries for concurrent and parallel programming. He also invented some of the most ...
In Agile Information Security, James Fitzer ...What is Acceptable Risk? Compliance and Agility Implementing Controls, Prevention, Monitoring, and Response Final Thoughts Bibliography About the Author