天天看點

springboot thymeleaf周遊List集合項目場景:代碼實作:

項目場景:

springboot項目,後端從資料庫擷取到資料集合傳回前端頁面,在頁面中對資料進行周遊顯示

springboot thymeleaf周遊List集合項目場景:代碼實作:

代碼實作:

springboot一般內建thymeleaf模闆引擎對集合資料進行展示渲染

導入springboot內建thymeleaf的兩個依賴(這裡用的是springboot父版本)

<dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
        </dependency>
           

頁面編寫

springboot thymeleaf周遊List集合項目場景:代碼實作:

 相關代碼

<!DOCTYPE html>
<html  xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>周遊集合資料</title>
</head>
<body>
<table align="center"  cellspacing="0" cellpadding="10px">
    <thead>
        <tr>
            <th>序号</th>
            <th>部門id</th>
            <th>部門名稱</th>
            <th>資料庫</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="dept,stat:${deptlist}">
            <td th:text="${stat.count}"></td>
            <td th:text="${dept.deptno}"></td>
            <td th:text="${dept.dname}"></td>
            <td th:text="${dept.db_source}"></td>
        </tr>
    </tbody>
</table>
</body>
</html>
           

效果圖

springboot thymeleaf周遊List集合項目場景:代碼實作:

繼續閱讀