Jac*_*ack 6 java spring spring-mvc
我在Spring中有以下表单显示错误消息.我想知道我什么时候应该使用spring:bind?这有什么区别呢?我研究了这些页面a,b但我仍然感到困惑.
1
<form:form method="post"
action="http://localhost:8080/project/calculator/process"
modelAttribute="keyPadForm">
Name1: <form:input type="text" path="name1" />
<form:errors path="name1" />
Run Code Online (Sandbox Code Playgroud)
2
<form:form method="post"
action="http://localhost:8080/project/calculator/process"
modelAttribute="keyPadForm">
<spring:bind path="name1">
Name1: <form:input type="text" path="name1" />
<form:errors path="name1" />
</spring:bind>
Run Code Online (Sandbox Code Playgroud)
在你的第二种情况下,spring:bind标签已过时,你的第一种形式
<form:form method="post"
action="http://localhost:8080/project/calculator/process"
modelAttribute="keyPadForm">
Name1: <form:input type="text" path="name1" />
<form:errors path="name1" />
Run Code Online (Sandbox Code Playgroud)
是一种语法糖,不使用form标签库的等价物,而只是常见的 HTML 表单标签,将基于spring:bind并且看起来像这样:
<spring:nestedPath path="keyPadForm">
<form method="post" action="http://localhost:8080/project/calculator/process">
<spring:bind path="name1">
Name1:<input type="text" name="${status.expression}" value="${status.value}">
<span class="fieldError">${status.errorMessage}</span>
</spring:bind>
</form>
</spring:nestedPath>
Run Code Online (Sandbox Code Playgroud)
在某些情况下,您可以做出改变,例如form:input始终是双向绑定,因此值被发送到服务器并显示当前值,其中spring:bind您可以通过省略来实现单向绑定,仅发送到服务器值eg <input type="text" name="${status.expression}">,但主要是form标签库提供了更方便的绑定相关标签
| 归档时间: |
|
| 查看次数: |
666 次 |
| 最近记录: |