zno2

重大发现 springmvc Controller 高级接收参数用法

1.  数组接收

    @RequestMapping(value="deleteRole.json")
    @ResponseBody
    public Object deleteRole(String[] ids){
        return systemService.deleteRole(ids);
    }

页面:

?ids=1&ids=2&ids=3

 

2. list 接收

package cn.zno.smse.pojo;

import java.io.Serializable;
import java.util.List;

public class SystemUser implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private List<SystemRole> roleList;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column SMSE_USER.ID
     *
     * @mbggenerated
     */
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column SMSE_USER.NAME
     *
     * @mbggenerated
     */
    private String name;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column SMSE_USER.USERNAME
     *
     * @mbggenerated
     */
    private String username;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column SMSE_USER.PASSWORD
     *
     * @mbggenerated
     */
    private String password;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column SMSE_USER.MOBILE
     *
     * @mbggenerated
     */
    private String mobile;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column SMSE_USER.EMAIL
     *
     * @mbggenerated
     */
    private String email;

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column SMSE_USER.ID
     *
     * @return the value of SMSE_USER.ID
     *
     * @mbggenerated
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column SMSE_USER.ID
     *
     * @param id the value for SMSE_USER.ID
     *
     * @mbggenerated
     */
    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column SMSE_USER.NAME
     *
     * @return the value of SMSE_USER.NAME
     *
     * @mbggenerated
     */
    public String getName() {
        return name;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column SMSE_USER.NAME
     *
     * @param name the value for SMSE_USER.NAME
     *
     * @mbggenerated
     */
    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column SMSE_USER.USERNAME
     *
     * @return the value of SMSE_USER.USERNAME
     *
     * @mbggenerated
     */
    public String getUsername() {
        return username;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column SMSE_USER.USERNAME
     *
     * @param username the value for SMSE_USER.USERNAME
     *
     * @mbggenerated
     */
    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column SMSE_USER.PASSWORD
     *
     * @return the value of SMSE_USER.PASSWORD
     *
     * @mbggenerated
     */
    public String getPassword() {
        return password;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column SMSE_USER.PASSWORD
     *
     * @param password the value for SMSE_USER.PASSWORD
     *
     * @mbggenerated
     */
    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column SMSE_USER.MOBILE
     *
     * @return the value of SMSE_USER.MOBILE
     *
     * @mbggenerated
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column SMSE_USER.MOBILE
     *
     * @param mobile the value for SMSE_USER.MOBILE
     *
     * @mbggenerated
     */
    public void setMobile(String mobile) {
        this.mobile = mobile == null ? null : mobile.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column SMSE_USER.EMAIL
     *
     * @return the value of SMSE_USER.EMAIL
     *
     * @mbggenerated
     */
    public String getEmail() {
        return email;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column SMSE_USER.EMAIL
     *
     * @param email the value for SMSE_USER.EMAIL
     *
     * @mbggenerated
     */
    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    public List<SystemRole> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<SystemRole> roleList) {
        this.roleList = roleList;
    }
}
SystemUser.java
    @RequestMapping(value="saveUserAdd.json")
    @ResponseBody
    public Object saveUserAdd(SystemUser user) {
        return systemService.saveUserAdd(user);
    }

页面:

<form>
    <tbody>
    <tr>
        <td colspan="2">
            <b>用户角色</b>
            <hr>
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" name="roleList[0].id" value="21943DC037B343EDE053433210AC4939" id="roleList_0">
            <label for="roleList_0">系统管理员</label>
        </td>
        <td>
            <input type="checkbox" name="roleList[1].id" value="38950038-53cd-11e6-9619-00163e001b41" id="roleList_1">
            <label for="roleList_1">b</label>
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" name="roleList[2].id" value="4bcb3f3c-53cd-11e6-9619-00163e001b41" id="roleList_2">
            <label for="roleList_2">c</label>
        </td>
        <td>
            <input type="checkbox" name="roleList[3].id" value="526dc5e4-53cd-11e6-9619-00163e001b41" id="roleList_3">
            <label for="roleList_3">d</label>
        </td>
    </tr>
    </tbody>
<form>

 

ps:

和struts2 的 ognl表达式不同之处在于:

 

框架 name的值
Struts2 user.roleList[0].id
SpringMVC roleList[0].id

posted on 2016-08-06 08:13  zno2  阅读(855)  评论(0编辑  收藏  举报

导航