SpringBoot 2.x series of tutorials (59) SpringBoot realizes the internationalization i18n function

Recently, the newly developed project needs to use the internationalization function. The project is developed based on SpringBoot. Take this opportunity to organize an article about SpringBoot's implementation of the internationalization i18n function and share it with you.

Dependency introduction

There is no need to introduce other special configuration in the Spring Boot web project, the basic components required are already covered in the default web starter. The corresponding dependent pom configuration is as follows:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.2.2.RELEASE</version>
</dependency>

International project structure

The project here is mainly for the external api interface, that is, the project that separates the front and back ends. Focus on the background internationalization configuration, and how to obtain the corresponding internationalized copy content according to the key in the interface use.

First look at the directory structure of the project as a whole:

image

Configure the parser

After the corresponding dependency is introduced above, it is first used to initialize the LocaleResolver class, which is the default resolver and is used to set the default international language for the current session.

/**
 * 配置国际化语言
 *
 **/
@Configuration

Guess you like

Origin blog.csdn.net/wo541075754/article/details/107190883