Springboot thymeleaf統合
6581 ワード
Springboot 2のthymeleaf統合は比較的簡単で、以下の手順に従います. pom.xmlにweb依存とthymeleaf依存を追加します.application.ymlは変更せずにデフォルトの構成を使用できます. srcmainjavacontrollerでIndexController を作成 srcmainresourcestemplatesでindexを作成します.html プロジェクトを実行し、ブラウザにアドレスを入力して結果を表示:localhost:8080/index 参照先:http://www.fengyunxiao.cn
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-thymeleafartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
dependencies>
@Controller
public class IndexController {
@RequestMapping("/index")
public String index(ModelMap map) {
map.put("text", "hello");
map.put("href", "http://www.fengyunxiao.cn");
return "index";
}
}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<input th:id="${text}" th:name="${text}" th:value="${text}" />
<a th:href="${href}" th:text="${text}"> a>
body>
html>