SpringMVC---3、绑定参数(封装集合)

1、实体类

package beans;

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

public class Collerction implements Serializable {
     private List<User> list;
     private Map<String,User> map;

    public List<User> getList() {
        return list;
    }

    public void setList(List<User> list) {
        this.list = list;
    }

    public Map<String, User> getMap() {
        return map;
    }

    public void setMap(Map<String, User> map) {
        this.map = map;
    }

    @Override
    public String toString() {
        return "Collerction{" +
                "list=" + list +
                ", map=" + map +
                '}';
    }
}

2、jsp页面********

list在声明的时候以中括号内声明第几个user元素

map类在中括号内单引号声明key值

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>hello</title>
</head>
<body>
<h1>绑定参数</h1>

        <%--封装list和map--%>
        <form action="/param2/test3" method="post">
            list姓名:<input type="text" name="list[0].username"><br>
            list年龄:<input type="text" name="list[0].age"><br>

            map姓名:<input type="text" name="map['one'].username"><br>
            map年龄:<input type="text" name="map['one'].age"><br>
            <input type="submit" value="猛击此处提交">
        </form>
</body>
</html>

3、controller类

package controller;

import beans.Collerction;
import beans.Info;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/param2")
public class ParamController2 {

    @RequestMapping("/test3")
    public String save2(Collerction collerction){
        System.out.println(collerction);

        return "success";
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值