Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

SpringMVC @ response Chinese garbled resolution

Shulou Source: shulou.com Published: 2022-06-03 04:14:18 10月03日 Update

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?

Tags: Chinese garbled cause method coding problem configuration powerful no need memory function that is newcomer way time format framework comments source code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Apple MariaDB macOS