spring - 按钮上的绑定列表单击 Thymeleaf
问题描述
我想要的是当我单击id=addUnitCharge
按钮时,id = proName
应该id=proAge
添加到id=property_type_tbl
正文中。当我单击提交按钮时,所有值都应分配给(id=code
并id=school
作为id=property_type_tbl
要列出的值和值unitCharge
)
这是我的 PlaAccount 课程
public class PlAccount{
private String code;
private String school;
private List<UnitCharge> unitCharge;
//Getters and Setters
}
UnitCharge 类
public class UnitCharge{
private String proName;
private String proAge;
//Getters and Setters
}
我的控制器类
@GetMapping(path = {"/product/add")
public String index(Model model) {
model.addAttribute("type", PlAccount.builder().build());
return "/loan/product/add";
}
@PostMapping("/coopmis/waterTariff/product/add")
public String save(@Valid PlAccount plAccount, BindingResult result){
plAccountService.savePlAccount(plAccount);
}
我的html
<form method="post" action="/product/add" th:object="${type}">
<input type="number" id="code" class="form-control" th:name="code">
<input type="number" id="school" class="form-control" th:name="school">
//On button click below Items should add to `property_type_tbl` table.
<input type="number" id="proName" class="form-control" th:name="proName">
<input type="number" id="proAge" class="form-control" th:name="proAge">
<button type="button" class="btn btn-success" id="addUnitCharge" onclick="addRowPropertyType()"
th:text="#{add}">Add
</button>
<div class="form-group">
<button type="submit" class="btn btn-success " th:text="#{submit}">Submit</button>
</div>
</form>
<div class="form-group">
<table class="table table-striped id="property_type_tbl">
<thead>
<tr>
<th th:text="#{proName}"></th>
<th th:text="#{proAge}"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
非常感谢您的支持。
解决方案
推荐阅读
- c++ - Why is my struct constructor, which contains other structs, not working?
- python - 关于 python 上 sort() 方法的一些问题
- javascript - mongoose find() 方法不是服务调用中的函数错误
- list - 在 Flutter 中调用函数时遇到空引用问题
- mysql - MYSQL 将毫秒转换为仅 MM:SS
- c# - 手动调整位图大小
- python - 无法加载 CSS Django IIS
- java - java.lang.NoClassDefFoundError:Tomcat 10 中的 jakarta/servlet/jsp/jstl/core/LoopTag
- docker - 为什么 vscode 的远程资源管理器会得到旧容器的列表?(码头工人)
- php - 为什么 Laravel `middleware('auth:sanctum')` 会导致 302 问题?