Spring MVC:弹簧之间的区别:bind和form:form [英] Spring MVC: Difference between spring:bind and form:form

查看:217
本文介绍了Spring MVC:弹簧之间的区别:bind和form:form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的JSP代码片段如下所示:



 < form:form modelAttribute =testRulesForm> 
....
< td>
< form:checkbox path =rules [$ {counter.index}]。isActivevalue =rules [$ {counter.index}]。isActive/>
< / td>
< td>
< form:select path =rules [$ {counter.index}]。leftCondition.name>
< form:options items =$ {testRulesForm.ruleAttributes}itemLabel =nameitemValue =name/>
< / form:select>
< / td>
< td>
< form:select path =rules [$ {counter.index}]。operator>
< form:options itemLabel =operatoritemValue =operator/>
< / form:select>
< / td>
....

看到我已经指定了路径变量,到我的modelAttribute,这是否意味着我不需要spring:bind?



谢谢

解决方案

如果您已经使用 form ,通常您不需要使用< spring:bind> c> taglib。

它们在模型属性方面基本相同,但来自 form taglib的标签也会生成HTML表单标记,而使用< spring:bind> ,您需要自己生成标记。

$ p $ lt; code>< form:form modelAttribute =foo> $ c> form
标签:


< form:input path =bar/>
< / form:form>

与下面的代码类似:< spring:bind>

 < spring:bind path =foo> 
< form method =get>
< spring:bind path =bar>
< input name =barvalue =$ {status.displayValue}/>
< / spring:bind>
< / form>
< / spring:bind>

< spring:bind> 很有用当你需要自定义的东西时, form taglib是无法实现的。


I am looking to find out the difference between the spring:bind and form:form tag libraries when submitting a form.

A snippet of my JSP is as follows:

<form:form modelAttribute="testRulesForm">
....
<td>
    <form:checkbox path="rules[${counter.index}].isActive" value="rules[${counter.index}].isActive"/>
</td>
<td>
    <form:select path="rules[${counter.index}].leftCondition.name">
        <form:options items="${testRulesForm.ruleAttributes}" itemLabel="name" itemValue="name" />
    </form:select>
</td>
<td>
    <form:select path="rules[${counter.index}].operator">
        <form:options itemLabel="operator" itemValue="operator" />
    </form:select>
</td>
....

Seeing as I have my path variable specified and this will be bound to my modelAttribute, does this mean that I do not need spring:bind?

Thanks

解决方案

Normally you don't need to use <spring:bind> if you already use form taglib.

They do basically the same with respect to model attributes, but tags from form taglib also generate HTML form markup, whereas with <spring:bind> you need to generate markup yourself.

The following code with form tags:

<form:form modelAttribute = "foo">
    <form:input path = "bar" />
</form:form>

is similar to the following code with <spring:bind>:

<spring:bind path = "foo">
    <form method = "get">
        <spring:bind path = "bar">
            <input name = "bar" value = "${status.displayValue}" />
        </spring:bind>
    </form>
</spring:bind>

<spring:bind> is useful when you need something customized, that cannot be achieved by form taglib.

这篇关于Spring MVC:弹簧之间的区别:bind和form:form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆