Thymeleaf th:字段不接受标记,它不显示数据

问题描述 投票:0回答:2

在我使用Spring启动和Thymeleaf的项目中,我尝试以表格格式发布值列表,

1)我制作一份实体清单,

List<EntFlatIncome> flatIncomeList

2)设置为Wrapper类,

WrpFlatIncome wrpFlatIncome = new WrpFlatIncome();
            wrpFlatIncome.setFlatIncomeList(flatIncomeList);

3)将ModelAndView保持为“ApproveBillList”HTML页面,包括列表数据

ModelAndView modelView = new ModelAndView("ApproveBillList");
modelView.addObject("wrpflatIncome", wrpFlatIncome);

在那个HTML页面我显示值而不是输入框,因为数据IsApproved布尔值只需更新其他列数据不需要修改用户This is a HTML page Design

当我尝试使用Thymeleaf提交数据时:对象只有IsApproved数据,其他列(PaidAmount,paidDate,paymentMode,transactionId,BillAmount)值仅为NULL,

在标签中,我习惯于像这样编码

<td>
       <label th:field="*{flatIncomeList[__${status.index}__].billAmount}"
      th:text="*{flatIncomeList[__${status.index}__].billAmount}"></label>
      </td>

如果我在输入框中粘贴:具有禁用属性的字段意味着它也只传递NULL,请帮助我...谢谢

这是完整的HTML代码

<div class="panel-body">
		<!-- Body Content Starts -->
		<form id="billformid" action="#"  method="post" th:action="@{/updatebill}" th:object="${wrpflatIncome}">
		
		<div class="table-responsive table-responsive-md"> 
	
	<table class="table table-hover">
	<thead>
	    <tr>
	  <th>isApproved</th>   
      <th>paidAmount</th>
      <th>paidDate</th>
      <th>paymentMode</th>
      <th>transactionId</th>
      <th>Bill Amount</th>
      
    </tr>
    </thead>
    
    <tbody>
    <tr th:each="flatIncomeList,status:*{flatIncomeList}" 
    th:if="${not #lists.isEmpty(wrpflatIncome.flatIncomeList)}">
    
       <td hidden="true">
      <input class="form-control" type="text"
       th:field="*{flatIncomeList[__${status.index}__].billId}"/>
      </td> 
      
      
       <td>
      <input type="checkbox" class="form-check-input"  
       th:field="*{flatIncomeList[__${status.index}__].isApproved}"/>
      </td> 
      
      <td th:field="*{flatIncomeList[__${status.index}__].paidAmount}">
      <label 
      th:text="*{flatIncomeList[__${status.index}__].paidAmount}"></label>
      </td>
      
      <td th:field="*{flatIncomeList[__${status.index}__].paidDate}">
       <label 
      th:text="*{flatIncomeList[__${status.index}__].paidDate}"></label>
      </td> 
      
      <td th:field="*{flatIncomeList[__${status.index}__].paymentMode}">
       <label 
      th:text="*{flatIncomeList[__${status.index}__].paymentMode}"></label>
      </td> 
      
      <td th:field="*{flatIncomeList[__${status.index}__].transactionId}">
       <label 
      th:text="*{flatIncomeList[__${status.index}__].transactionId}"></label>
      </td> 
      
       <td>
       <label th:field="*{flatIncomeList[__${status.index}__].billAmount}"
      th:text="*{flatIncomeList[__${status.index}__].billAmount}"></label>
      </td> 
      
      <!-- version not shown in html -->
        <td hidden="true">
      <input class="form-control" type="text"
       th:field="*{flatIncomeList[__${status.index}__].version}"/>
      </td> 
    </tr>
    </tbody>
    
	</table>
	</div>
	
	<div class="text-center">
	<button type="submit" class="btn btn-primary">Submit</button>
	<button type="reset" class="btn btn-danger">Reset</button>
	</div>
		
		
		
		</form>
		<!-- Body Content Ends -->
			</div>

@Controller

@PostMapping("/updatebill")
public ModelAndView doUpdateBillApproveStatus(@ModelAttribute WrpFlatIncome wrpflatIncome) 
{
    ModelAndView modelView = new ModelAndView();
    try {
        if(wrpflatIncome.getFlatIncomeList()!=null) {

            //Boolean result = serbillSave.doUpdateApprovedBillList(wrpflatIncome.getFlatIncomeList());
        }

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return modelView;
}
html spring-boot thymeleaf
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.