在一些开发中可能会涉及到某些页面需要进行国际化显示的业务,此时通过SpringBoot可以很好的实现。

参考页面如下:

SpringBoot-web端国际化显示

页面国际化可分为两种形态:

1.根据浏览器语言进行设置。

2.根据用户选择进行设置。

虽然两种形态,但是同样的实现方法。

开发环境:

IDEA:2019.3.1

SpringBoot:2.2.5

步骤一:引入相应的静态资源及thymeleaf模板引擎。

为了演示方便,我将静态资源全部引入项目,并且引入了模板引擎thymeleaf,pom文件如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>2.2.5.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.seegot</groupId>
12     <artifactId>spring-boot-web-restful-01</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>spring-boot-web-restful-01</name>
15     <description>Demo project for Spring Boot</description>
16 
17     <properties>
18         <java.version>1.8</java.version>
19         <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
20         <!-- 布局功能的支持程序 thymeleaf3主程序  layout2以上版本-->
21         <!--thymeleaf2 layout1-->
22         <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
23     </properties>
24 
25     <dependencies>
26         <dependency>
27             <groupId>org.springframework.boot</groupId>
28             <artifactId>spring-boot-starter-web</artifactId>
29         </dependency>
30         <!--引入jquery-->
31         <dependency>
32             <groupId>org.webjars</groupId>
33             <artifactId>jquery</artifactId>
34             <version>3.4.1</version>
35         </dependency>
36         <!--引入bootstrap-->
37         <dependency>
38             <groupId>org.webjars</groupId>
39             <artifactId>bootstrap</artifactId>
40             <version>4.4.1-1</version>
41         </dependency>
42         <dependency>
43             <groupId>org.webjars</groupId>
44             <artifactId>chartjs</artifactId>
45             <version>26962ce-1</version>
46         </dependency>
47         <dependency>
48             <groupId>org.webjars</groupId>
49             <artifactId>popper.js</artifactId>
50             <version>2.0.2</version>
51         </dependency>
52         <dependency>
53             <groupId>org.projectlombok</groupId>
54             <artifactId>lombok</artifactId>
55         </dependency>
56         <dependency>
57             <groupId>org.springframework.boot</groupId>
58             <artifactId>spring-boot-starter-thymeleaf</artifactId>
59         </dependency>
60         <dependency>
61             <groupId>org.springframework.boot</groupId>
62             <artifactId>spring-boot-starter-test</artifactId>
63             <scope>test</scope>
64             <exclusions>
65                 <exclusion>
66                     <groupId>org.junit.vintage</groupId>
67                     <artifactId>junit-vintage-engine</artifactId>
68                 </exclusion>
69             </exclusions>
70         </dependency>
71     </dependencies>
72 
73     <build>
74         <plugins>
75             <plugin>
76                 <groupId>org.springframework.boot</groupId>
77                 <artifactId>spring-boot-maven-plugin</artifactId>
78             </plugin>
79         </plugins>
80     </build>
81 
82 </project>
View Code

相关文章: