Spring Boot Thymeleaf 实现国际化 (2)

中文简体语言配置文件messages.properties

text.title=国际化示例 text.home=首页 text.language=语言 text.language.chinese=中文(简体) text.language.english=英语 text.home.message=你好,欢迎你 text.description=这是个国际化模板示例

英文语言配置文件messages.properties

text.title=Application title text.home=Home text.language=Language text.language.chinese=Chinese text.language.english=English text.home.message=Hi, welcome! text.description=It is a i18n demo 5.最后贴上maven配置文件pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 "> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.easy</groupId> <artifactId>template-thymeleaf</artifactId> <version>0.0.1</version> <name>template-thymeleaf</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <encoding>UTF-8</encoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <dependencies> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 运行示例 1.找到TemplateThymeleafApplication.java文件运行示例

地址栏输入: :8080/

运行效果分别如下

默认为中文语言环境

Spring Boot Thymeleaf 实现国际化

切换到英文环境后,界面效果如下

Spring Boot Thymeleaf 实现国际化

资料

Spring Cloud Feign 示例源码

Spring Boot、Spring Cloud示例学习

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyffwp.html