MustacheとはSpring Bootのテンプレートエンジンです。
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mustache</artifactId> </dependency>
controller
package com.example.demo;
import java.util.Date;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HelloController {
@RequestMapping("/hello-mst")
public String hello(
@RequestParam(defaultValue="World")String name,
Map<String, Object> model
) {
model.put("name", name);
model.put("date", new Date());
return "hello-mst";
}
}
html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello Mustache</title>
</head>
<body>
<div>
<p><b>Message:</b>Hello, {{name}}</p>
<p><b>Date:</b>{{date}}</p>
</div>
</body>
</html>
あら、うまくいかんね。