I had a lot of chances to fix Spring MVC, but I haven't used Boot so much, so I will move it as a review.
Mac OS X 10.12 Java 1.8.0_92 Spring Tool Suite 3.8.4 Spring Boot 1.5.3 thymeleaf 2.1.5
DL and install Java from Oracle Official.
Download and install Spring Tool Suite (hereinafter "STS") from Official.
Project creation Created with STS as follows
Java
SampleController.java
package com.example;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/sample")
public class SampleController {
@RequestMapping(method = RequestMethod.GET)
public String test(Model model) {
model.addAttribute("name", "Kusagi API");
model.addAttribute("get", "GET /sample");
model.addAttribute("post", "POST /sample");
return "sample/index";
}
}
HTML
index.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>top page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h2 th:text="${name}"></h2>
<p th:text="${get}" />
<p th:text="${post}" />
</body>
</html>
It worked as expected
Recommended Posts