zoukankan      html  css  js  c++  java
  • springboot thymeleaf ----服务端渲染html

    一、 引用命名空间 <html xmlns:th="http://www.thymeleaf.org"> 不这么写 html标签没闭合会报错

    二、实际内容在../static//font-awesome/css/font-awesome.css

    引入css
    <link th:href="@{/font-awesome/css/font-awesome.css}" rel="stylesheet" />

    引入js
    <script type="text/javascript" th:src="@{/js/jquery-1.11.2.min.js}"></script>

    三、输出内容

    <p th:text="#{home.welcome}">Welcome to our grocery store!</p>
    th:utext 用来显示“unescaped ” 的html内容
    th:text="${today}" ${today} 用来引用 today 变量

    四、 

    访问对象
    ${param.x} 返回名为x 的 request参数。(可能有多个值)

    ${session.x} 返回名为x的Session参数。

    ${application.x} 返回名为 servlet context 的参数。

    五、

    #{home.welcome(${session.user.name})} -- 格式化数据

    #ctx: the context object.
    #vars: the context variables.
    #locale: the context locale.
    #request: (only in Web Contexts) the HttpServletRequest object.
    #response: (only in Web Contexts) the HttpServletResponse object.
    #session: (only in Web Contexts) the HttpSession object.
    #servletContext: (only in Web Contexts) the ServletContext object.

    日期:
    ${#calendars.format(today,'dd MMMM yyyy')}

    六、

    星号语法

    <div th:object="${session.user}">
    <p>Name: <span th:text="*{firstName}">Sebastian</span>.</p>
    <p>Surname: <span th:text="*{lastName}">Pepper</span>.</p>
    <p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p>
    </div>

    七、

    输出URL

    <a href="product/list.html" th:href="@{/product/list}">Product List</a>

    <a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>

    八、

    使用代码段

    <div th:insert="~{commons :: main}">...</div>
    <div th:if="${user.isAdmin()} == false"> --输出布尔表达式

    <tr th:class="${user.id}? 'even' : 'odd'">
    ...
    </tr>

    九、

    预处理

    <p th:text="${__#{article.text('textVar')}__}">Some text here...</p>


    设置任何Attribute 的方法

    <input type="submit" value="Subscribe!" th:attr="value=#{subscribe.submit}"/> --设置单个

    <img src="../../images/gtvglogo.png" th:attr="src=@{/images/gtvglogo.png},title=#{logo},alt=#{logo}" /> --一次设置多个

    十、

    循环
    <tr th:each="prod : ${prods}">
    <td th:text="${prod.name}">Onions</td>
    <td th:text="${prod.price}">2.41</td>
    <td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
    </tr>

  • 相关阅读:
    Python
    Python
    Python
    Python
    Python
    《The Rise and Fall of Scala》scala的兴衰
    Scala核心编程_第05章_函数式编程
    IntelliJ IDEA scala的源码设置
    Scala核心编程_第04章 程序流程控制
    Scala核心编程_第03章_运算符
  • 原文地址:https://www.cnblogs.com/moneyss/p/11977818.html
Copyright © 2011-2022 走看看