Springboot page internationalization (refer to Mad God)


insert image description here
First of all, we prepare some resources. The purpose is to create a folder i18n under the resource for better display effect , which is used to store the internationalization configuration folder. springboot has a
insert image description here
insert image description here
default internationalization automatic configuration. MessageSourceProperties is found to be a configuration file, the prefix is ​​spring.meaagse, we click into this class: find the message and open the global configuration file of springboot at this time: configure the page internationalization value to get the internationalization value on the page, check the Thymeleaf documentation, find The message value operation is: #{…}. Let's go to the page to test and refresh the homepage: It means that our configuration files have all taken effect , but we want to be better! Can automatically switch between Chinese and English according to the button! Configure internationalization parsing:

insert image description here

insert image description here

insert image description here

insert image description here


insert image description here

insert image description here

There is an internationalized Locale (area information object) in Spring; there is a resolver called LocaleResolver (getting area information object) in it!

Let's go to our webmvc automatic configuration file and look for it! See SpringBoot default configuration:
insert image description here
AcceptHeaderLocaleResolver There is a method in this class
insert image description here
, so if we want to click the link now to make our internationalized resources take effect, we need to make our own Locale take effect!

Let's write our own LocaleResolver, which can carry regional information on the link!

Modify the jump link of the front-end page:
insert image description here
let's write a custom component class for processing!
insert image description here
In order to make our regionalization information take effect, inject beans under our own MvcConofig;
insert image description here
restart the project to take effect
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_46533159/article/details/126759732