Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SpringMVC @ response Chinese garbled resolution

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Newcomers learn the springMVC development framework and use ajax to get the return value through @ response.

I have to say that @ response is very powerful, and it saves a lot of trouble to package the return class directly into json format.

But if the return value is of String type, there will be Chinese garbled problem. I tried to make some adjustments and checked many methods on the Internet. Sum up here.

1. Add comment produces = {"application/json;charset=UTF-8"}

@ RequestMapping (value = "/ method.do", produces = {"application/json;charset=UTF-8"})

It is suitable for a small amount, and it has to be added every time a method is written, which is not suitable for unified processing.

two。 Add configuration and configure String encoding in springMVC-*.xml, as follows

.

If you can look at the source code of the org.springframework.http.converter.StringHttpMessageConverter class, you will find that the default encoding mode is "ISO-8859-1".

This should be the main reason for our Chinese garbled code.

We have to complain here that many jar packages written by foreigners have the problem of garbled codes in Chinese. The main reason is that people don't use Chinese. Therefore, it is certain to choose "ISO-8859-1" with a small memory footprint.

When will we all be able to use utf-8?

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report