Spring Boot基本上 “Hello World”
首先
继续上次的内容,在创建项目后,使用Thymeleaf来显示Hello World。
依据其作为参考进行实施
目录
- 
- 包裝結構
 
 
- 
- 建立HTML和Controller
 
 
- 
- 啟動Spring Boot專案
 
 
- 
- HTML和Controller之間的關係
 
 
- 參考文獻
 
包装结构

创建HTML,控制器
在「resources」-「templates」目录下创建index.html文件
※「resources」-「templates」文件夹下的内容是Thymeleaf的默认引用位置,可以进行更改。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
  <head>
    <title>Hello</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>任意タイトル</h1>
    <h2><span th:text="${message}"></span></h2>
  </body>
</html>
在com.example.demo.controller的包下创建HelloWorldController.java。
package com.example.demo.controller;
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
public class HelloWorldController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String helloWorld(Model model) {
        model.addAttribute("message", "Hello World!!");
        return "index";
    }
}
启动Spring Boot项目
①点击项目右键→选择 “运行”→选择 “Spring Boot 应用程序”以启动Spring Boot项目
②在浏览器中访问 “http://localhost:8080/”

HTML和Controller之间的关系

文献引用
- 
- Spring Boot+Thymeleafで”Hello World”を作成する
 
 
- アノテーションについて