In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what to do when spring boot solves the problem of returning json to the foreground after returning Chinese garbled code to the foreground. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Spring boot solves the Chinese garbled code when the background returns json to the foreground.
Spring boot solution background return json to the foreground Chinese garbled code, error 500:no convertter for return value of type, Chinese returned to the browser garbled parsed into question mark?
Detailed error information Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException:No converter found for return value of type: class www.it399.com.controller.file.ResultBean
The background returns json to the foreground to solve the problem of Chinese garbled code. 1. Solve the configuration of Chinese garbled code
@ Configuration
@ EnableWebMvc
@ ComponentScan
Public class MvcConfiguration extends WebMvcConfigurerAdapter {
@ Bean
Public HttpMessageConverter responseBodyConverter () {
StringHttpMessageConverter converter = new StringHttpMessageConverter (Charset.forName ("UTF-8"))
Return converter
}
@ Override
Public void configureMessageConverters (List > converters) {
Super.configureMessageConverters (converters)
/ / resolve Chinese garbled
Converters.add (responseBodyConverter ())
/ / after the above configuration is added to solve the Chinese garbled code, the error 500:no convertter for return value of type will be reported directly when the json data is returned.
Converters.add (messageConverter ())
}
}
In addition to the above configuration, MappingJackson2HttpMessageConverter is also added.
@ Bean
Public MappingJackson2HttpMessageConverter messageConverter () {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter ()
Converter.setObjectMapper (getObjectMapper ())
Return converter
}
Note: if responseBodyConverter and MappingJackson2HttpMessageConverter are configured separately to ensure that the former is not overwritten, otherwise springboot will be returned and json will be returned normally, but garbled code will be returned, or the Chinese will not be messed up, but an object or json exception will be returned. 3. Complete code to solve springboot Fan Hu Chinese garbled code and return json 500error
/ * *
* spring boot solves the problem of garbled Chinese characters when the backend returns json to the foreground
* http://www.it399.com/blog/index.jsp
, /
@ Configuration
@ EnableWebMvc
@ ComponentScan
Public class MvcConfiguration extends WebMvcConfigurerAdapter {
@ Bean
Public HttpMessageConverter responseBodyConverter () {
StringHttpMessageConverter converter = new StringHttpMessageConverter (Charset.forName ("UTF-8"))
Return converter
}
@ Bean
Public ObjectMapper getObjectMapper () {
Return new ObjectMapper ()
}
@ Bean
Public MappingJackson2HttpMessageConverter messageConverter () {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter ()
Converter.setObjectMapper (getObjectMapper ())
Return converter
}
@ Override
Public void configureMessageConverters (List > converters) {
Super.configureMessageConverters (converters)
/ / resolve Chinese garbled
Converters.add (responseBodyConverter ())
/ / after the above configuration is added to solve the Chinese garbled code, the error 500:no convertter for return value of type will be reported directly when the json data is returned.
Converters.add (messageConverter ())
}
}
This is about what to do when spring boot solves the problem of returning json to the foreground after returning the Chinese garbled code to the foreground. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.