thymeleaf

1.配置文件在application.yml:

server:
  port: 8900
spring:
  # THYMELEAF
  thymeleaf:
    #開啓模板緩存(默認值:true)
    cache: false
    #Check that the template exists before rendering it.
    check-template: true
    #檢查模板位置是否正確(默認值:true)
    check-template-location: true
    #開啓MVC Thymeleaf視圖解析(默認值:true)
    enabled: true
    #模板編碼
    encoding: UTF-8
    #要運用於模板之上的模板模式。另見StandardTemplate-ModeHandlers(默認值:HTML5)
    mode: LEGACYHTML5
    #在構建URL時添加到視圖名稱前的前綴(默認值:classpath:/templates/)
    prefix: classpath:/templates/
    #在構建URL時添加到視圖名稱後的後綴(默認值:.html)
    suffix: .html
    #Thymeleaf模板解析器在解析器鏈中的順序。默認情況下,它排第一位。順序從1開始,
    #只有在定義了額外的TemplateResolver Bean時才需要設置這個屬性。
    template-resolver-order: 1

2.新建html文件:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>welcome</title>
    <meta http-equiv="Content-Type" content="text/html;    ch arset=UTF-8"/>
    <link rel="stylesheet" type="text/css" media="all" href="../../css/gtvg.css" th:href="@{/css/gtvg.c ss}"/>
</head>
<body>
<p th:text="'hello, ' + ${name} + '!'"/>
</body>
</html>

 

3.新建controller:

運行http://localhost:8900/hello

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章