Согласно официальному документу, строки по умолчанию кодируются с использованием UTF-8. Я исследовал автоматически настроенные MustacheViewResolver и MustacheResourceTemplateLoader, оба имеют свойство charset, установленное на «UTF-8», но когда я добавляю китайское слово «中文», оно не отображается должным образом.
Кто-нибудь знает решение? Заранее спасибо.
Вот 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<artifactId>spring-boot-sample-web-mustache</artifactId>
<name>spring-boot-sample-web-mustache</name>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
код:
//main class
@SpringBootApplication
public class SampleWebMustacheApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebMustacheApplication.class, args);
}
}
//controller
@Controller
public class WelcomeController {
private String message = "Hello World";
@RequestMapping("/home")
public String home(Map<String, Object> model) {
model.put("time", new Date());
model.put("message", this.message);
return "home";
}
}
и шаблон с китайским словом «中文» в нем:
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
Date: {{time.date}}
<br>
Time: {{time.time}}
<br>
Message: {{message}}中文
</body>
</html>