天天看点

SpringBoot中thymeleaf的th:each用法,给name动态赋值

做一个功能,在页面动态增加人员信息,页面如下图

当我修改这条数据时,需要回显,可能是多条,后台用的List<实体> 接收的,name格式必须是locationPersonnel[0].tel,所以就要用th:each的下表拼接这种写法了;

<div class="panel panel-custom" th:each="locationPersonnel,locationPersonnelStat : ${locationPersonnelList}">

th:attr="name='locationPersonnel['+${locationPersonnelStat.index}+'].name'"
我是这样给name属性动态赋值的,写好好久好久了。

记住这是用于多条数据修改回显的时候写的,至于注册的时候,自己用js拼接就OK了
           

若描述不争取请加 739749855qq详解

SpringBoot中thymeleaf的th:each用法,给name动态赋值

继续阅读