Thymeleaf与JavaScript的踩坑

  • 以前用jsp的时候,在js中用${abc}就可以拿到后台model.addAttribute中key为abc的值,但是在Thymeleaf中,必须得先在js标签上这么写:
<script th:inline="javascript">

然后用[[ ${abc} ]]拿到值,同时记住

<script th:inline="javascript">
    projects=JSON.parse([[${subjects}]])
    layui.use('table', function(){
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            ,height: 312
            ,cols:
                [
                    [ //表头
                        {field: 'id', title: 'ID', width:80, sort: false, fixed: 'left'},
                        {field: 'subjname', title: '课设题目', width:80},
                        {field: 'teachername', title: '负责老师', width:80}
                    ]
            ],
            data:projects,//[{"id":"0","name":"adsf","teachername":"asdf"}],
            skin: 'line' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [10, 20, 30]
            , limit: 10 //每页默认显示的数量

        });

    });
</script>

里面的cols:[[……]]一定不能写成下面这样:

<script th:inline="javascript">

然后用[[ ${abc} ]]拿到值,同时记住

<script th:inline="javascript">
………………
            cols:[[ //表头
                        {field: 'id', title: 'ID', width:80, sort: false, fixed: 'left'},
                        {field: 'subjname', title: '课设题目', width:80},
                        {field: 'teachername', title: '负责老师', width:80}
                    ]],
………………
</script>

因为Thymeleaf会以为是内联[[${……}]],很扯。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Thymeleaf与Spring Boot的交互可以通过引入Spring Boot的Thymeleaf依赖来实现。首先,您需要在项目的pom.xml文件中添加以下依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> ``` 这样就可以使用Thymeleaf来处理前端页面了。在处理前端页面时,我们常常需要将页面中的共同部分拿出来放到一个单独的页面中,这样可以利用Thymeleaf对共同部分进行重复使用。通过使用Thymeleaf的语法,我们可以在页面中使用Thymeleaf的标签来引用其他页面或者共享的片段。 例如,可以使用Thymeleaf的`th:include`标签来引入其他页面的内容,或者使用`th:replace`标签来替换当前标签的内容为其他页面的内容。另外,Thymeleaf还提供了丰富的语法来访问模型中的数据,进行条件判断和循环等操作。 总的来说,Thymeleaf与Spring Boot的交互主要是通过引入Thymeleaf依赖,并使用Thymeleaf的语法在页面中进行数据绑定和页面片段的引用。这样可以更方便地进行前端页面的开发和管理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Thymeleaf与springboot的简单整合](https://blog.csdn.net/weixin_57128596/article/details/122783663)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CtrlZ1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值