spring mvc示例代碼(使用SimpleFormController表單控制)

 使用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 則執行相應的請求。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章