需求:扩展spring 3 mvc表单绑定功能,使其能绑定多个command对象,且绑定对象规则按照 model.name 格式进行bind。
描述:spring 3 mvc现有表单绑定功能推荐用 form标签,且仅支持一个 command对象直接的绑定,
<form:form commandName="someCommand1">
</form:form>
绑定规则默认约定按照model的属性名进行匹配,现有的功能存在至少2个弊端:1)不支持多个command 对象绑定;2)如果要绑定除了command外的对象或者参数,必须不能重复现有绑定command 对象中的属性名。
解决思路有2个,本人推荐第2个:
1、form表单中input的name还是按照model.name格式,在 controller中form表单提交方法的签名为:method(HttpServerRequest request,……),在方法中遍历request中的参数,手工的bind。实现手工bind可以写个单独的工具类,用BeanWrapper wrapper = new BeanWrapperImpl(obj)来解决,具体的请参照ss3ex 中的工具类。
2、构建一个实现FactoryBean接口的超类,取名为CommandFactoryBean。以分页需求为例,学生信息分页,表单有2个对象,一个是page对象,另一个是学生对象。CommandFactoryBean类中包含2个属性,一是page类,第二个属性就是通过FactoryBean接口方法getObject()得到的绑定的model类(这里为学生类)。前台from表单:
<form:form commandName="commandFactoryBean">
<form:input path="page.pageNo"/>
<form:input path="student.name"/>
</form:form>
后台controller中方法签名就是
method(……,CommandFactoryBean commandFactoryBean)
肯定还有其他的解决办法,看到的请直接留言。
分享到:
相关推荐
ycsb-hbase14-binding-0.17.0
jgoodies-binding-2_6
node-sass-windows-x64-93-binding.node文件下载
使用beans-binding的经验和技巧
RSS-XML Data-Binding to Data Control with Row Limitations。
win32-x64-51-57-59-64-67-72-79-83_binding.node多版本.zip
3.0.5.RELEASE.jar,org.springframework.asm-3.0.5.RELEASE.jar,org.springframework.aspects-3.0.5.RELEASE.jar,org.springframework.beans-3.0.5.RELEASE.jar,org.springframework.binding-2.3.0.RELEASE.jar...
工程文件 博文链接:https://starscream.iteye.com/blog/1072179
win32-ia-32-48_binding.node插件去掉node不报错win32-ia-32-48_binding.node插件去掉node不报错win32-ia-32-48_binding.node插件去掉node不报错win32-ia-32-48_binding.node插件去掉node不报错win32-ia-32-48_...
java运行依赖jar包
A-PUF-FSM-Binding-Scheme-for-FPGA-IP-Protection-and-Pay-per-Device-Licensing
The Spring Framework Chapter 2: Model 2 and the MVC Pattern Chapter 3: Introduction to Spring MVC Chapter 4: Annotation-Based Controllers Chapter 5: Data Binding and the Form Tag Library Chapter 6: ...
官方版本,亲测可用
ucrop-android-binding-master.rar
neo4j rest封装项目的war包,如果需要源代码可以在csdn资源中搜索neo4j-java-rest-binding,有个neo4j-java-rest-binding.zip的文件下载,但里面没有jar,因为项目使用maven管理jar包,如果不习惯使用maven,可将此...
铜碳体系DFTB参数拟合,殷迪,李震宇,本文针对铜表面结构,发展了一套相应铜碳原子的DFTB参数。在电子部分参数中,单中心参数通过自由原子全电子DFT计算获得并固定,双�
linux-x64-64_binding.node资源
node-sass-windows-x64-72-binding.node文件下载
node-sass-windows-x64-108-binding.node文件下载
node-sass-windows-x64-111-binding.node文件下载