spring boot thymeleaf

引入支持

<dependency>
	<groupId>org.thymeleaf</groupId>
	<artifactId>thymeleaf-spring5</artifactId>
	<version>3.0.9.RELEASE</version>
</dependency>

配置application.yml

spring:
  thymeleaf:
    cache: false
    suffix: .html
    #prefix: classpath:/templates/  默认值

在resourse/templates/下建立index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
   welcome
</body>
</html>

控制器 LongController.java

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

@RequestMapping("login")
@Controller
public class LoginController {
    @RequestMapping("login")
    public String login(){
        System.out.println("aaaa");
        return "index";
    }


}

启动项目,浏览器访问 http://localhost:8080/login/login  

  

  

原文地址:https://www.cnblogs.com/ZenoPan/p/9227585.html