SpringMVC数据绑定

来源:互联网 发布:淘宝海外直购能退货吗 编辑:程序博客网 时间:2024/05/29 16:28

1.编写一个自定义的数据类型(bean)

2.编写PropertyEditor(继承PropertyEditorSupport),重写setAsText()和getAsText()方法。

3.JSP页面,在<spring:nestedPath path="你的bean名字">中包含form表单,form中的action不指定动作的话,浏览器会将表单提交回原始的URI(在使用SimpleFormController的情况下)

4.写Controller(继承SimpleFormController),在构造函数中setCommandName();setCommandClass();setFormView();setSuccessView();等等,

然后重写onsubmit和initBinder方法,在initBinder方法中调用binder.registerCustomEditor,用于注册2中的PropertyEditor,在onsubmit得到JSP提交的bean运行逻辑。

5.在xml中注入bean(Controller)。

0 0
原创粉丝点击