pom.xml

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  4. </dependency>

Controller

  1. @Controller
  2. public class PageController {
  3. @RequestMapping("/page")
  4. public String page3(Model model){
  5. model.addAttribute("userName","张三");
  6. return "hello";
  7. }
  8. @RequestMapping("info/more")
  9. public String page2(){
  10. return "hello2";
  11. }
  12. @RequestMapping("sys/index")
  13. public String page(){
  14. return "sys/index";
  15. }
  16. @RequestMapping("/Hi")
  17. public ModelAndView sayHello() {
  18. ModelAndView modelAndView = new ModelAndView();
  19. modelAndView.setViewName("hello");
  20. modelAndView.addObject("key", 12345);
  21. //System.out.println("test");
  22. return modelAndView;
  23. }
  24. }

resource/templates中添加vm

  • 譬如hello.vm 中(和上面的一致)
    1. <html>
    2. <head>
    3. <meta charset="UTF-8"/>
    4. <title>Insert title here</title>
    5. </head>
    6. <body>
    7. <h1>this is the hello.html in templates</h1>
    8. <span th:text="${key}"></span>
    9. </body>
    10. </html>