当前位置: 首页 > 知识库问答 >
问题:

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

扈高逸
2023-03-14

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

1)我列出一个实体清单,

List<EntFlatIncome> flatIncomeList

2)设置为包装类,

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

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

如果我在输入框中输入th:field with disabled attibute意味着它也只传递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>

@控制器

@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;
}

共有1个答案

云承天
2023-03-14

不应在labeltd上使用th:field属性。它不会像预期的那样工作;浏览器不会提交这些元素的任何数据。

相反,您应该使用inputs。它可以是只读的:

<input type="text" th:field="*{myField}" readonly="readonly"/>

或隐藏:

<input type="hidden" th:field="*{myField}"/>
 类似资料:
  • 我正在使用Logback登录我的应用程序。我使用的是HTMLLayout,我的msg已经格式化,但当logbak打印该msg时,它不会显示格式化的msg 我的logback代码是: 消息示例: HTTP请求:User:unknown-Path:resorts-Header:{host=[localhost:8022],connection=[keep alive],content-length=[

  • 我有一个网站,我想运行购物车功能的完整过程。一切顺利,直到我点击付款方式,选择借记卡和。在将数据放入字段时,它不接受。如何将数据放入字段中。以下是测试网站的链接:https://vapesuite.allomate.solutions/#/.下面是将数据输入字段的代码。

  • 这个代码过去是有效的,但我不确定我改变了什么,或者在传单中改变了什么来打破它,但没有显示标记。数据正确返回,正在创建标记对象,但未显示任何标记。我在这里不知所措。使用0.7.2。让我给你看看代码。。。 } 一切都应该很好。服务器正确返回信息。列表中始终有13项(预期行为),我将plostlist[I]的内容以及plotmarker对象打印到控制台。 以下是plotlist[i]的输出: 一切看起来

  • 问题内容: 所以我有这张表 现在,如果我查询 我期待类似的东西 是否有可能 ? PS:C行中的内容仅表示该列为空。 问题答案: 您可以创建一个嵌套表架构对象类型: 然后按以下方式构造查询: 例子: 结果:

  • 我希望将行插入到表中,但这些行被回显,但没有显示在表中。 项目的HTML代码为: 项目的main.js文件是:它从下面的PHP文件中取数据: 项目的PHP代码是:

  • 我正在学习Jupyter笔记本的降价单元格,并尝试使用以下代码为我的一本笔记本创建一个简单的深红色标题: 在Jupyter笔记本中,当我运行单元格时,这变成了一个深红色的标题,正如预期的那样,这里有一个大纲:http://datascience.ibm.com/blog/markdown-for-jupyter-notebooks-cheatsheet/. 当我将笔记本上传到GitHub时,我的J