我正在使用html,thymeleaf,Spring MVC进行应用程序,我想将表数据发送到spring控制器,但是当我点击应用程序的save按钮时,在控制台上出现错误:

java.lang.IllegalStateException:在org.thymeleaf org.springframework.web.servlet.support.BindStatus . (BindStatus.java:144)的bean名称'salesProduct [0]'的BindingResult和普通目标对象都不能作为请求属性使用.spring4.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:396)

浏览器错误:

HTTP状态500 - 请求处理失败;嵌套异常是org.thymeleaf.exceptions.TemplateProcessingException:执行处理器'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor'时出错(销售:290)

我在控制器中添加了三个属性,如salesBean,paymentBean和salesProductFormBean,你可以在下面的spring控制器代码中看到这是html的原因我没有在表单标签中添加th:object =“$ ” .

HTML

Sales.html

<form th:action="@{/salesForm}" method="post" class="mainData"
        id="form">
        <div class="buttonBar" id="mainbutton">
            <div>
                <button class="btn" id="save" type="submit">
                    <img th:src="@{/resources/images/save.svg}" /> Save
                </button>
                <button class="btn" id="reset" onclick="clearForm()" type="reset">
                    <img th:src="@{/resources/images/reset.svg}" /> Reset
                </button>
                <button type="button" class="btn" id="clientNew">
                    <img th:src="@{/resources/images/notebook.svg}" /> Client Creation
                </button>
            </div>
        </div>

        <div class="container">
            <div class="mp-pusher" id="mp-pusher">
                <nav id="mp-menu" class="mp-menu"></nav>
                <div class="scroller-inner"></div>

                <div class="containerMain">
                    <div class="mainArea">
                        <div class="inputArea">

                            <div class="ccode">
                                <lable class="lable">Client code</lable>
                                <input type="text" class="inputfield" id="ccode"
                                    th:field="*{salesBean.client.clientId}" />
                                <button type="button" class="inputbutton" id="clientData"></button>
                            </div>

                            <div>
                                <ul class="tabs" data-persist="true">
                                    <li><a href="#tab1" id="first">Basic data</a></li>
                                    <li><a href="#tab2" id="second">Payment</a></li>
                                </ul>

                                <div class="tabcontents">
                                    <div id="tab1">
                                        <div class="invNo">
                                            <lable class="lable">Invoice number</lable>
                                            <input type="text" id="invNo" th:field="*{salesBean.salesId}"
                                                name="salesId" class="inputfield disabled"
                                                readonly="readonly" />
                                        </div>

                                        <div class="invdate calendar">
                                            <lable class="lable">Invoice date</lable>
                                            <input type="date" class="inputfield" id="invdate"
                                                th:field="*{salesBean.invoiceDate}" /> <span
                                                class="calendar"><img
                                                th:src="@{/resources/images/calendar.svg}" /></span>
                                        </div>

                                        <div class="txtChallan">
                                            <lable class="lable">Challan number</lable>
                                            <input type="text" class="inputfield" id="txtChallan"
                                                th:field="*{salesBean.challanNumber}" />
                                        </div>

                                        <div class="txtChallDt calendar">
                                            <lable class="lable">Date</lable>
                                            <input type="date" class="inputfield" id="txtChallDt"
                                                th:field="*{salesBean.challanDate}" /> <span
                                                class="calendar"><img
                                                th:src="@{/resources/images/calendar.svg}" /></span>
                                        </div>

                                        <div class="txtPO">
                                            <lable class="lable">P. O. ID</lable>
                                            <input type="text" class="inputfield" id="txtPO"
                                                th:field="*{salesBean.purchaseOrderId}" />
                                        </div>

                                        <div class="txtPoDt calendar">
                                            <lable class="lable">Date</lable>
                                            <input type="date" class="inputfield" id="txtPoDt"
                                                th:field="*{salesBean.purchaseOrderDate}" /> <span
                                                class="calendar"><img
                                                th:src="@{/resources/images/calendar.svg}" /></span>
                                        </div>
                                    </div>

                                    <div id="tab2">
                                        <div class="txtCash">
                                            <lable class="lable">Cash</lable>
                                            <input type="number" class="inputfield" id="txtCash"
                                                th:field="*{paymentBean.cash}" />
                                        </div>

                                    </div>

                                </div>
                                <!-- tabcontents -->
                            </div>
                            <!-- blank -->
                            <!-- for autocomplete -->
                            <div class="ui-widget" id="autocomplete_desc">
                                <div class="tableArea">
                                    <div class="tablePanel">
                                        <div class="tableButtonBar">Material entry</div>
                                        <section class="tableHolder">
                                            <table id="invoicetable" class="transactionTable table"
                                                cellpadding="0" cellspacing="0">
                                                <thead>
                                                    <tr>
                                                        <th>Serial</th>
                                                        <th>Description</th>
                                                        <th>Nos.</th>
                                                        <th>Quantity</th>
                                                        <th>Rate</th>
                                                        <th>Amount</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr
                                                        th:each="salesProduct, stat: *{salesProductFormBean.salesProducts}">
                                                        <td th:text="${stat.count}">1</td>

                                                        <td><input type="text"
**Line no: 290**                                                            th:field="*{salesProduct[__${stat.index}__].numbers}" /></td>
                                                        <td><select type="select" class="selectfield"
                                                            id="product"
                                                            th:field="*{salesProduct[__${stat.index}__].product.productId}">
                                                                <option value="Select"></option>
                                                                <option th:each="prdList : ${productList}"
                                                                    th:value="${prdList.productId}"
                                                                    th:text="${prdList.productName}"></option>
                                                        </select></td>
                                                        <td><input type="number"
                                                            th:field="*{salesProduct[__${stat.index}__].quantity}" /></td>
                                                        <td><input type="number"
                                                            th:field="*{salesProduct[__${stat.index}__].rate}" /></td>
                                                        <td><input type="number"
                                                            th:field="*{salesProduct[__${stat.index}__].amount}" /></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </section>
                                    </div>
                                    <!-- tablePanel -->
                                </div>
                                <!-- tableArea -->
                            </div>
                        </div>
                        <!-- inputArea -->

                    </div>
                    <!-- mainArea -->
                </div>
                <!-- containerMain -->
            </div>
            <!-- /container -->
        </div>
    </form>

调节器

@Autowired
private List<SalesProduct> salesProducts= new ArrayList<SalesProduct>();

@ModelAttribute("salesProducts")
    public List<SalesProduct> salesProducts() {
        return  salesProducts;
    }

 @RequestMapping(value= "/sales", method = RequestMethod.GET)
    public String salesInvoicePage(final ModelMap model) {  

        String userName = LoginController.getPrincipal();
        model.addAttribute("user", userName);
        model.addAttribute("salesBean",  new Sales());
        model.addAttribute("paymentBean",  new Payment());

        SalesProductForm salesProductForm = new SalesProductForm();   

        SalesProduct salesProduct= new SalesProduct();
        salesProducts.add(salesProduct);
        salesProductForm.setSalesProducts(salesProducts);
        model.addAttribute("salesProductFormBean",  salesProductForm);
        //model.addAttribute("salesProducts", salesProducts);

        List<Product> productList= productService.list();
        model.addAttribute("productList", productList);

        return "sales";
    }

模型

public class SalesProduct implements java.io.Serializable {

    private Integer salesProductId;
    private Product product;
    private UserDetail userDetailByModifiedBy;
    private UserDetail userDetailByCreatedBy;
    private Date createdDate;
    private Date modifiedDate;
    private String numbers;
    private Float quantity;
    private Float rate;
    private Float amount;
    private Set<Sales> saleses = new HashSet<Sales>(0);

    //Setter and Getters
}

public class SalesProductForm {
    private List<SalesProduct> salesProducts;

    public List<SalesProduct> getSalesProducts() {
        return salesProducts;
    }

    public void setSalesProducts(List<SalesProduct> salesProducts) {
        this.salesProducts = salesProducts;
    }
}

我陷入了这个问题,但不知道我错过了什么 . 有谁知道我做错了什么?