重大发现 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
时间: 2024-11-07 06:34:44

重大发现 springmvc Controller 高级接收参数用法的相关文章

springmvc传递参数与接收参数

springmvc和structs的接收参数的映射原理是一样的一.表单代码<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3

springmvc 传参和接收参数

对于springmvc接收参数有那些方式,下面我写了几个. 先创建项目,导入jar包配置web.xml ,springmvc-servlet.xml上面有过介绍,在本章最下面配置信息也写了出来. 通过HttpServletRequest 获取参数 @RequestMapping(value="par1.do") public ModelAndView par1(HttpServletRequest request){ // 接收前台传来的参数 String userName = req

springmvc 传递和接收数组参数

java url中如何传递数组,springMVC框架controller类如何接收数组参数? 下面介绍一下URL中传递数组参数方法: dd.do?titles[]=col1&titles[]=col2&titles[]=col3 或者使用ajax方式传递: var param = {titles:['col1','col2','col3']};  $.ajax({url:"dd.php", type:"post", data:param, asyn

springmvc请求接收参数的几种方法

通过@PathVariabl注解获取路径中传递参数 转载请注明出处:springmvc请求接收参数的几种方法 代码下载地址:http://www.zuidaima.com/share/1751862044773376.htm JAVA [java] view plaincopy @RequestMapping(value= " /{id}/{str} " ) public ModelAndView helloWorld(@PathVariable String id, @PathVar

实用———springmvc接收参数校验

https://www.cnblogs.com/funyoung/p/8670550.html https://www.cnblogs.com/monkeydai/p/10068547.html [email protected] 两粒种子,一片森林. 首页 新随笔 联系 订阅 管理 随笔 - 21  文章 - 0  评论 - 8 两粒种子,一片森林. 首页 新随笔 联系 订阅 管理 随笔 - 21  文章 - 0  评论 - 8 SpringMVC参数校验 使用SpringMVC时配合hibe

Spring+MVC Controller层接收App端请求的中文参数乱码问题。

在正文之前,说明下Filter的作用: 过滤器顾名思义就是进行过滤的,可以实现代码的定向执行和预处理.通俗点说法filter相当于加油站,request是条路,response是条路,目的地是servlet,这个加油站设在什么地方对什么数据操作可以由你来控制.备注:过滤器可以再请求和响应之前做一部分预处理,有效的过滤掉不需要的内容,而且过滤器可以被复用,节省了大量的复用代码,提高了java的代码执行效率 java的Controller层接收App的请求时,请求的参数是中文,服务器端接收到的是乱码

SpringMVC Controller 介绍

一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ,然后再把该Model 返回给对应的View 进行展示.在SpringMVC 中提供了一个非常简便的定义Controller 的方法,你无需继承特定的类或实现特定的接口,只需使用@Controller 标记一个类是Controller ,然后使用@RequestMapping 和@RequestParam 等一些注

SpringMVC Controller 介绍[转]

原文:http://haohaoxuexi.iteye.com/blog/1753271 SpringMVC Controller 介绍 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ,然后再把该Model 返回给对应的View 进行展示.在SpringMVC 中提供了一个非常简便的定义Controller 的方法,你无需继承特定的类或实现特定的接口,只需使用

SpringMVC Controller介绍

SpringMVC Controller 介绍 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ,然后再把该Model 返回给对应的View 进行展示.在SpringMVC 中提供了一个非常简便的定义Controller 的方法,你无需继承特定的类或实现特定的接口,只需使用@Controller 标记一个类是Controller ,然后使用@RequestMap