使用SimpleFormController表单控制适合添加、更新,并且可以显示两个页面(第一个页面是用户输入数据页面,第二个页面是用户完成操作后显示的页面)
1、web.xml
将以下代码覆盖相应代码:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/com/ztenc/oa/mfp/springConfig/mfp-data.xml,
/WEB-INF/classes/com/ztenc/oa/mfp/springConfig/mfp-service.xml,
/WEB-INF/classes/com/ztenc/oa/mfp/springConfig/config/mfp-user.xml
</param-value>
</context-param>
2、mfp-servlet.xml
将以下代码覆盖相应代码,其它的映射关系我待会添加:
<bean id="simpleUrlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order">
<value>0</value>
</property>
<property name="mappings">
<props>
<!--用户权限管理-->
<prop key="user/groupcreate.htm">groupCreateController</prop>
</props>
</property>
</bean>
3、
mfp-user.xml示例配置:
<bean id="groupCreateController" class="com.ztenc.oa.mfp.web.user.UpGroupCreateController">
<property name="commandClass">
<value>com.ztenc.oa.mfp.bean.UpGroup</value>
</property>
<property name="formView">
<value>user/groupadd</value>
</property>
</bean>
control类
package com.ztenc.oa.mfp.web.user;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.ztenc.oa.mfp.bean.UpGroup;
public class UpGroupCreateController extends SimpleFormController {
@Override
protected ModelAndView onSubmit(Object command) throws Exception {
UpGroup bean = (UpGroup)command;
String name =bean.getName();
return new ModelAndView("user/grouplist","agroup",bean);
}
}
jsp页面重要代码:
<form method="post" action="groupcreate.htm">
<table >
<tr>
<td >添加群组信息</td>
</tr>
<tr>
<td >组名</td>
<td >
<input type="text" name="name">
</td>
</tr>
<tr>
<td >父类</td>
<td >
<input type="text" name="parent">
</td>
</tr>
<tr>
<td >
</td>
</tr>
</table><input type="submit" value="添加" name="button2">
</form>
在IE中输入请求命令:http://127.0.0.1:7070/mfp/user/groupcreate.htm 则执行相应的请求。
spring mvc示例代码(使用SimpleFormController表单控制)
最新推荐文章于 2024-06-15 20:07:11 发布