導(dǎo)入相關(guān)依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
ThymeleafProperties 配置類
1.默認(rèn)編碼
2.前綴
3.后綴
相當(dāng)于視圖解析器?
package com.kuang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
//templates在這個(gè)目錄下的所有頁(yè)面,只能通過(guò)controller來(lái)訪問,相當(dāng)于一起的WEB-INF目錄
//需要導(dǎo)入模板引擎
//模板引擎是視圖解析器,只能通過(guò)服務(wù)器轉(zhuǎn)發(fā),請(qǐng)求是請(qǐng)求不到的,拼接獲取html,靜態(tài)資源實(shí)現(xiàn)的是,路徑映射。有優(yōu)先級(jí)。
public class IndexController {
@RequestMapping("/index")
public String index(){
return "/test";
}
}
?
這是學(xué)SpringBoot的必經(jīng)之路,非常重要!?。。ǔ悄闶菍W(xué)前端的)
?
只改了前端代碼點(diǎn)一下這個(gè)就可以刷新?
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("msg","hello springboot");
return "/test";
}
?
傳值過(guò)來(lái)了?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-624057.html
th:text="${msg}"爆紅,但是可以顯示,F(xiàn)ile->Settings->Editor->Inspection ?取消“Expression variables validation”的勾選文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-624057.html
到了這里,關(guān)于thymeleaf模板引擎的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!