首页 > 解决方案 > 按钮上的绑定列表单击 Thymeleaf

问题描述

我想要的是当我单击id=addUnitCharge按钮时,id = proName应该id=proAge添加到id=property_type_tbl正文中。当我单击提交按钮时,所有值都应分配给(id=codeid=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>

非常感谢您的支持。

标签: springspring-bootspring-mvcthymeleaf

解决方案


推荐阅读