Answers:
如果查看支持元素的FormTag(4.3.x)源代码<form>,则会注意到这一点
/**
* Set the name of the form attribute in the model.
* <p>May be a runtime expression.
*/
public void setModelAttribute(String modelAttribute) {
this.modelAttribute = modelAttribute;
}
/**
* Get the name of the form attribute in the model.
*/
protected String getModelAttribute() {
return this.modelAttribute;
}
/**
* Set the name of the form attribute in the model.
* <p>May be a runtime expression.
* @see #setModelAttribute
*/
public void setCommandName(String commandName) {
this.modelAttribute = commandName;
}
/**
* Get the name of the form attribute in the model.
* @see #getModelAttribute
*/
protected String getCommandName() {
return this.modelAttribute;
}
它们都指的是同一领域,因此具有相同的作用。
但是,正如字段名所指示的那样,modelAttribute应该首选,正如其他人也指出的那样。
<tag-name>Tag。对于完全限定的类名.jar,spring-web在这种情况下,请打开包含标签的库()。在下面META-INF,您会找到spring-form.tld。这将有一个<tag>入境form与<tag-class>的org.springframework.web.servlet.tags.form.FormTag。
旧方式= commandName
...
<spring:url value="/manage/add.do" var="action" />
<form:form action="${action}" commandName="employee">
<div>
<table>
....
新方法= modelAttribute
..
<spring:url value="/manage/add.do" var="action" />
<form:form action="${action}" modelAttribute="employee">
<div>
<table>
..