1、引入模板thymeleaf

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency> 

增加配置

spring:
  thymeleaf:
    prefix: classpath:/templates/

  

 

2、增加接口

    @RequestMapping("/hello")
    public String helloHtml(HashMap<String, Object> map) {
        map.put("hello", "hello world~");
        return "/index";
    }

  

3、创建Html页面 index.html 路径为:resources/templates/index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>Title</title>
</head>
<body>
    <p th:text="${hello}"></p>
</body>
</html>

  

4、查看效果

Spring Boot使用Html

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-05-15
  • 2021-12-05
  • 2021-08-31
  • 2022-12-23
  • 2021-10-07
  • 2021-05-24
猜你喜欢
  • 2021-11-18
  • 2021-11-17
  • 2021-12-09
  • 2021-07-04
  • 2021-08-26
  • 2022-12-23
相关资源
相似解决方案