Spring Boot使用Html

一、引入模板thymeleafhtml

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

增長配置java

spring:
  thymeleaf:
    prefix: classpath:/templates/

  

 

二、增長接口spring

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

  

三、建立Html頁面 index.html 路徑爲:resources/templates/index.htmlapp

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

  

四、查看效果spring-boot

相關文章
相關標籤/搜索