Thymeleaf

/ 默认分类 / 0 条评论 / 2041浏览

Thymeleaf+SpringMVC,在html中获取数据session、request参数的值


Session属性

比如后台为session添加了一个sessionValue属性,和Request参数访问方式类似,这里使用session前缀:

<div th:text="${session.sessionValue}">[...]</div>

同样的,还可以使用#httpSession方式访问,它直接进入javax.servlet.http.HttpSession对象。

Spring beans

Thymeleaf可以通过@beanName访问Spring应用上下文中注册的bean,如

<div th:text="${@urlService.getApplicationUrl()}">...</div>

在这个例子中,@urlService就是在上下文中注册的Spring Bean的名字:
请输入图片描述
日历以行为单位每行分割


> 日历每月至少4行,每行7天,即每月从1号到最后一天,至少占用4行空间,5行为90%,6行为10%,因此可以对行进行区分,当然最好还是用thymeleaf实现队列
<!--The table calendar comes here-->
<table id="calendar" class="table">
    <tbody>
        <tr th:each="i:${#numbers.sequence(1,6)}">
            <th:block th:if="${i==1}">
                <td th:if="${calendar.dayOfWeek ne 1}" th:each="j:${#numbers.sequence(1,calendar.dayOfWeek-1)}"> </td>
                <td th:each="j:${#numbers.sequence(1,8-calendar.dayOfWeek)}">
                    <h2 th:text="${calendar.cDays[j-1].day}"></h2>
                    <h3></h3>
                    <ul class='list-unstyled'>
                        <li th:each="event:${calendar.cDays[j-1].event}" th:text="${event.event}" class="myEvent"></li>
                    </ul>
                </td>
            </th:block>
            <th:block th:if="${i==2}">
                <td th:each="j:${#numbers.sequence(1,7)}">
                    <h2 th:text="${calendar.cDays[9-calendar.dayOfWeek-2+j].day}"></h2>
                    <h3></h3>
                    <ul class='list-unstyled'>
                        <li th:each="event:${calendar.cDays[9-calendar.dayOfWeek-2+j].event}" th:text="${event.event}" class="myEvent"></li>
                    </ul>
                </td>
            </th:block>
            <th:block th:if="${i==3}">
                <td th:each="j:${#numbers.sequence(1,7)}">
                    <h2 th:text="${calendar.cDays[16-calendar.dayOfWeek-2+j].day}"></h2>
                    <h3></h3>
                    <ul class='list-unstyled'>
                        <li th:each="event:${calendar.cDays[16-calendar.dayOfWeek-2+j].event}" th:text="${event.event}" class="myEvent"></li>
                    </ul>
                </td>
            </th:block>
            <th:block th:if="${i==4}">
                <td th:each="j:${#numbers.sequence(1,7)}">
                    <h2 th:text="${calendar.cDays[23-calendar.dayOfWeek-2+j].day}"></h2>
                    <h3></h3>
                    <ul class='list-unstyled'>
                        <li th:each="event:${calendar.cDays[23-calendar.dayOfWeek-2+j].event}" th:text="${event.event}" class="myEvent"></li>
                    </ul>
                </td>
            </th:block>
            <th:block th:if="${i==5}">
                <td th:each="j:${#numbers.sequence(1,7)}">
                    <th:block th:if="${(i-1)*7+j-calendar.dayOfWeek+1} le ${calendar.days}">
                        <h2 th:text="${calendar.cDays[30-calendar.dayOfWeek-2+j].day}"></h2>
                        <h3></h3>
                        <ul class='list-unstyled'>
                            <li th:each="event:${calendar.cDays[30-calendar.dayOfWeek-2+j].event}" th:text="${event.event}" class="myEvent"></li>
                        </ul>
                    </th:block>
                </td>
            </th:block>
            <th:block th:if="${i==6}">
                <td th:each="j:${#numbers.sequence(1,7)}">
                    <th:block th:if="${(i-1)*7+j-calendar.dayOfWeek+1} le ${calendar.days}">
                    <h2 th:text="${calendar.cDays[37-calendar.dayOfWeek-2+j].day}"></h2>
                        <h3></h3>
                        <ul class='list-unstyled'>
                            <li th:each="event:${calendar.cDays[37-calendar.dayOfWeek-2+j].event}" th:text="${event.event}" class="myEvent"></li>
                        </ul>
                    </th:block>
                </td>
            </th:block>
        </tr>
    </tbody>
</table>