<!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

springboot 传值到页面
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";
    }
}




相关文章:

  • 2022-01-27
  • 2021-08-22
  • 2022-01-12
  • 2021-05-24
  • 2021-10-04
  • 2021-09-29
猜你喜欢
  • 2022-12-23
  • 2021-07-08
  • 2021-12-08
  • 2022-12-23
  • 2021-10-25
相关资源
相似解决方案