Maison > Article > interface Web > SpringMVC 页面向后台传输数据怎么做_html/css_WEB-ITnose
| 序号 | 告警开始时间 | 告警恢复时间 | 铁塔ID | 铁塔名称 | 站点名称 | 触发告警类型 | 告警级别 | 是否确认 | 告警详情 |
---|---|---|---|---|---|---|---|---|---|---|
| ${vs.index+1} | ${var.alarm_start_time} | ${var.alarm_end_time} | ${var.device_id} | ${var.device_name} | ${var.device_name} | ${var.alarm_type_name} | ${var.alarm_level_name} | ${var.is_confirm_name} | |
确认 删除 导出 | ${page.pageStr} |
把你的列表用一个form围住,action就填你的spring mvc的RequestMapping的value,
在springmvc中可以用requestParam获取post过来的,至于怎么调用mybatis的dao,方法调方法会吧。。
再不懂让懂的人来写吧。或者去好好看看spring reference
当我点击那个按钮时,怎么获取那个id,
当我点击那个按钮时,怎么获取那个id,
package com.springblank.form;/** * * @author xiaofanku */public class CityForm { private String[] cities; public String[] getCities() { return cities; } public void setCities(String[] cities) { this.cities = cities; } }
package com.springblank.controller;import com.springblank.form.CityForm;import java.util.Arrays;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;/** * * @author xiaofanku */@Controllerpublic class HomeController { @RequestMapping public String echo( @RequestParam("region")String region, HttpServletRequest request, Model model){ model.addAttribute("region", region); model.addAttribute("htRegion", request.getParameter("region")); return "query"; } @RequestMapping public String checkbox(Model model){ model.addAttribute("cityForm",new CityForm()); return "checkbox"; } @RequestMapping public String editCity(@ModelAttribute("cityForm") CityForm bean,Model model){ System.out.println(Arrays.toString(bean.getCities())); model.addAttribute("cityForm",bean); return "checkbox"; }}
<%@page contentType="text/html" pageEncoding="UTF-8"%><%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %><!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>您喜欢哪个城市</h1> <form:form modelAttribute="cityForm" action="editCity.htm"> <form:checkbox path="cities" value="1"/>上海 <form:checkbox path="cities" value="2"/>杭州 <form:checkbox path="cities" value="3"/>北京 <form:checkbox path="cities" value="4"/>广州 <form:checkbox path="cities" value="5"/>西安 <input type="submit" value="提交"/> </form:form> </body></html>
基础的springblank代码,在我的blog中有下载,另外spring reference也有form标签的示例。
如果value的值是中文在web.xml中加上spring的字符过滤器
<filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>