您的位置:首页 > 编程语言 > Java开发

springMVC_后台自动接受map数据

2013-06-19 09:47 225 查看
jsp:

<form action="/hello/getMap" method="post">

<input name="mapVo['a'].name">

<input name="mapVo['a'].password" type="password">

<input name="mapVo['b'].name">

<input name="mapVo['b'].password" type="password">

<input type="submit" value="submit">

</form>

java:

@RequestMapping(value="/getMap",method=RequestMethod.POST)

public void getMap(MapVo mapVo){

Set set = mapVo.getMapVo().keySet();

Iterator iterator = set.iterator();

while(iterator.hasNext()){

Object name = iterator.next();

PersonVo p = mapVo.getMapVo().get(name);

System.out.print(name+" "+p.getName()+" "+p.getPassword());

System.out.println();

}

}

public class MapVo {

private Map<String,PersonVo> mapVo;

public Map<String, PersonVo> getMapVo() {

return mapVo;

}

public void setMapVo(Map<String, PersonVo> mapVo) {

this.mapVo = mapVo;

}

}

public class PersonVo {

private String name;

private String password;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

}

通过以上代码,springMVC可以自动用map接受前台的数据,key是String类型的。

原文地址:http://blog.csdn.net/asarja/article/details/8978286
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: