IntelliJ, Springboot_view

3565 ワード

1.controller


/helloにマッピング
package hello.helloword.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HelloController {

    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data","hello"); 
        return "hello"; 
    }
}

return "hello";


hello.html除去レンダリング(thymeleafエンジンの処理)

2.templates/html

<!DOCTYPE HTML>
<html xmlns:th="http//www.thymeleaf.org">
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p th:text="'안녕하세요.' +${data}" >안녕하세요!!!!!</p>
</body>
</html>
${data}キーの値は「hello」です.

3.成果