springBoot整合thymeleaf

pom.文件

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.21</version>
    </dependency>

配置文件

spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#\u5F00\u53D1\u65F6\u5173\u95ED\u7F13\u5B58,\u4E0D\u7136\u6CA1\u6CD5\u770B\u5230\u5B9E\u65F6\u9875\u9762
spring.thymeleaf.cache=false


<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" >


<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- <link rel="stylesheet" href="../css/style.css"> -->
    <script th:src="@{/js/jquery-3.0.0.min.js}"></script>
    <style>
        table tr th,
        table tr td {
            width: 100px;
        }
    </style>
</head>


<body>
    <div>
        <table border="1">
        <thead id="tr">
        </thead>
        <tbody id="body">
     
        </tbody>    
        </table>
        <script type="text/javascript">
        $.ajax({
            url: "http://localhost:8080/sbsys/testdao",
            type:"get",
            dataType:'json',
            success:function (data) {
            console.log(data);
            console.log(data.columns);
                //循环表头的标题 
                var str="<tr>" +
                "<td>"+data.columns[1]+"</td>" +
                "<td>"+data.columns[2]+"</td>" +
                "<td>"+data.columns[0]+"</td>" +
                "<td>"+data.columns[4]+"</td>" +
                "<td>"+data.columns[3]+"</td>" +
                "<td>"+data.columns[5]+"</td>" +
                "</tr>";
              
                $("#tr").html(str);
                //循环表的内容 
                console.log(data.rows);
                var table="";
                for(var j=0;j<data.rows.length;j++)
                {
               
                table+="<tr>" +
                     "<td>"+data.rows[j].id+"</td>" +
                     "<td>"+data.rows[j].keyword+"</td>" +
                     "<td>"+data.rows[j].cid+"</td>" +
                     "<td>"+data.rows[j].parentA_cid+"</td>" +
                     "<td>"+data.rows[j].parentA_Name+"</td>" +
                     "<td>"+data.rows[j].parentB_Name+"</td>" +
                     "</tr>";
                }
                $("#body").html(table);  
            },
            error:function (data) {
                console.log(data);
            }
        })
        
        
        
        </script>
        
        
    </div>
</body>


</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值