utf 8 - Spring Boot Mustache doesn't render UTF-8 correctly -
according official document, strings encoded using utf-8 default. investigated auto-configed mustacheviewresolver , mustacheresourcetemplateloader, both have charset property set "utf-8", when add chinese word "中文", doesn't display properly.
does know solution? in advance.
here pom.xml ( merely official example ):
<?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>
the code:
//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"; } }
and template, chinese word "中文" in it:
<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>
i had resolved issue upgrading latest version of spring boot.
simply update pom.xml modify version number:
<parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.2.5.release</version> </parent>
1.2.5 latest stable version (as of writing).
Comments
Post a Comment