什么时候前台页面会传数组给后台? 复选框标签
》》数组
(1)前台代码 多个复选框表单,并把复选框选中的内容,发给给服务器后台,服务器去接收。
demo01_array.jsp
<%-- 页面会将选中的复选框的值,需要让复选框使用同一个name 程序认为需要将多个值 放到数组中,提交到后台 --%> <form method="post" action="${pageContext.request.contextPath}/delete1.action"> <input type="checkbox" value="1" name="ids"/> 第 1条记录<br/> <input type="checkbox" value="2" name="ids"/> 第 2条记录<br/> <input type="checkbox" value="3" name="ids"/> 第 3条记录<br/> <input type="submit" value="提交数据到后台" > <br/> </form>(2)后台代码 页面如果是提交的复选框的数据,则返回的是数组,我需要使用数组来接收。 (3)注意: 这里形参数组的名字必须和表单复选框的name属性的值一致
Demo01Controller
@Controller public class Demo01Controller { @RequestMapping("delete1.action") public ModelAndView test01(Integer[] ids){//参数只需要写数组 System.out.println(Arrays.toString(ids));//[1, 3] return null; } }(1)定义一个新类,类中定义一个数组成员变量
public class A{ private 数据类型[] 变量名; }(2)前台代码 表单 带 复选框,复选框使用同一个name (3)后台代码 方法参数为 新定义类
MyQueryOV
public class MyQueryOv { private Integer[] ids; public Integer[] getIds() { return ids; } public void setIds(Integer[] ids) { this.ids = ids; } }Demo01Controller
@RequestMapping("delete2.action") public ModelAndView test02(MyQueryOv ov){//参数只需要写QueryOV类 System.out.println(Arrays.toString(ov.getIds())); return null; }