文章目錄
- 1. 導入依賴
- 2. 配置
- 2. 視圖層
- 3. 建立頁面
- 4. 檢查target
- 5. 表達式
使用Thymeleaf 一共5步,檢查一下看看是否符合規範
1. 導入依賴
<!--模闆引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2. 配置
application.properties
# thymeleaf相關配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
2. 視圖層
做路徑跳轉
package com.imooc.dianping.controller.admin;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/admin/admin")
public class AdminController {
@GetMapping("/index")
public ModelAndView index() {
ModelAndView modelAndView = new ModelAndView("/admin/admin/index");
return modelAndView;
}
}
3. 建立頁面
預設:在templates目錄下面建立頁面
根據業務需求,在templates建立子包路徑,和視圖層相對應
4. 檢查target
5. 表達式
<p th:text="${name}"></p>