W
W
Wan-Derer2021-12-06 12:46:15
Java
Wan-Derer, 2021-12-06 12:46:15

Spring MVC, how to set default page encoding?

Hello :)
There is a REST API on Spring MVC (without Spring Boot if that matters).
Different points should return different MIME types (some JSON, some TEXT). In the case of JSON with Cyrillic, everything is fine, but "text" points return a page with ISO-... encoding and, accordingly, questions instead of Cyrillic.

Treated at the method annotation level, for example:

@DeleteMapping(value = "/employees/{id}", produces = "text/html; charset=utf-8")
// дальше сам метод


But I think it's a bit of a crutch. If there is a way to globally write somewhere that if text/html is returned, use utf-8 encoding?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-12-06
Hasanly @azerphoenix

Good afternoon.
In general, this is not a crutch method, but very normal.
But if you want to add it globally, you can extend the AbstractHttpMessageConverter class
Here is a similar question on SO -
https://stackoverflow.com/questions/5019162/custom...
Here is another similar question:
https://stackoverflow.com/questions /5649329/utf-8-...
https://stackoverflow.com/questions/6638284/spring...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question