最近學習springmvc的表單標簽庫,其中form標簽主要用於渲染HTML表單,而form標簽有很多屬性,可供選擇,其中一般來說(以前)最重要的是commandName屬性,因為它定義了模型屬性的名稱,包含了一個backing object,其屬性是用來填充說生成的表單的內容的。同時,使用此屬性要求在后台的請求處理方法中添加相應的模型屬性進行返回,這樣commandName才能生效,簡單代碼如下:
<form:form action="/book_save" method="post" commandName="book">
model.addAttribute("book", new Book());
最終的結果如題所示:Unable to find setter method for attribute: [commandName]。
解釋下原因:
學習的內容較舊了,貼出spring-form.tld中的一點東西
<attribute> <description>DEPRECATED: Use "modelAttribute" instead.</description> <name>commandName</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute>
這個屬性其實已經過時了,現在應該使用modelAttribute屬性,使用方法相同。
