springboot 傳值到頁面


 

 

 

<!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8" />
 5     <title></title>
 6 </head>
 7 <body>
 8 <h1 th:text="${host}">Hello World</h1>
 9 </body>
10 </html>


 編寫HelloController.java

復制代碼
package com.springboot.test;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

    @RequestMapping("/")
    public String index(ModelMap map) {
        // 加入一個屬性,用來在模板中讀取
        map.addAttribute("host", "Spring test");
        // return模板文件的名稱,對應src/main/resources/templates/index.html
        return "index";
    }
}





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM