SpringMVC——form标签的使用
-----------------------------------------------------------------------------------
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<!--Springform表单标签:form:input 、form:password、form:hidden、form:textarea:对应HTML表单的Text、password、hidden、textarea标签 -->
<!-- form:radiobutton:单选框组建标签,对那个表单bean对应的属性和value值相等时,单选框被选中。 -->
<!-- form:radiobuttons:单选框组件标签,用于构造多个单选框
-items:可以是一个list、String【】或者map
-itemValue:指定radio的value值。可以是集合中的bean的一个属性值
-itemLabel:指定radio的label值
-delimiter:多个单选框可以通过delimiter指定分割符 -->
<!--form:checkbox:复选框组件。用户构造单个复选框
form:checkboxs:用户构造多个复选框。使用方式同form:radiobuttons标签
form:select:用于构造下拉框组件,使用方式等同于form:radiobuttons标签
form:option :下拉框选项组件标签。使用方式等同于form:radiobuttons标签
from:errors:显示表单组件或数据校验所对应的错误 -->
<body>
<!--springform标签:可以快速的开发表单页面,可以进行表单回显 modelAttribute制定此表单对应的form表单,需要在RequestMapping里边放入对应表单-->
<form:form action="addUser" method="POST" modelAttribute="user">
id:<form:input path="id"/><br>
username:<form:input path="name" />
<br>
pwd:<form:password path="pwd" />
<br>
email:<form:input path="email" />
<br>
department:<form:select path="department.id" items="${departments}"
itemLabel="name" itemValue="id"></form:select>
<br>
<%
HashMap<String, String> sex = new HashMap<String, String>();
sex.put("0", "女");
sex.put("1", "男");
request.setAttribute("sex", sex);
%>
sex:<form:radiobuttons path="sex" items="${sex}" />
<br>
<input type="submit" value="submit">
</form:form>
</body>
</html>
-------------------------------------------------------------------------
/**
* @Controller注解:将该类表示为控制器
*/
@Controller
public class UserHandler {
/**
* @Autowired 注释,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。 通过 @Autowired的使用来消除 set
* ,get方法。
*/
@Autowired
private UserDao userDao;
@Autowired
private DepartmentDao departmentDao;
/**
* @RequestMapping("/addUser")使用requestMapping来映射URL method对应的请求方式
*/
@RequestMapping(value = "addUser", method = RequestMethod.POST)
public String saveUser(User user) {
System.out.println(user.toString());
userDao.saveUser(user);
return "redirect:/users";
}
/**
* @RequestMapping("/addUser")使用requestMapping来映射URL method对应的请求方式
*/
@RequestMapping(value = "addUser", method = RequestMethod.GET)
public String addUser(Map<String, Object> map) {
map.put("departments", departmentDao.getDepartments());
map.put("user", new User());
return "addUser";
}
/**
* @RequestMapping("/list")使用requestMapping来映射URL
*/
@RequestMapping("/users")
public String list(Map<String, Object> map) {
map.put("users", userDao.getUsers());
return "list";
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
版权声明:本文为博主原创文章,未经博主允许不得转载。
SpringMVC——form标签的使用的更多相关文章
- springmvc的form标签
1.要使用Spring MVC提供的表单标签,首先需要在视图页面添加: <%@ taglib prefix="form" uri="http://www.sprin ...
- springMvc <form:form>标签 <form:input>标签需要注意的问题
在用springMVC <form:form>表单时,喜欢报的错误如下所示: 错误的Controller层的代码如下: @RequestMapping(value = "test ...
- SpringMVC form 表单提交报400错误
错误代码: HTTP Status 400 - type Status report message description The request sent by the client was sy ...
- 如何用Spring框架的<form:form>标签实现REST风格的增删改查操作
1.首先创建两个bean类,Employee(职工)和Department(部门),一个部门可以有多个职工 Employee类(属性:职工ID:id:姓名:lastName:邮箱:email:性别:g ...
- s:form标签
2017-01-07 17:43:18 基本的用法 <!-- Action类必须有一个无参的构造器,因为在执行action方法之前,拦截器已经创建了一个"空"的Action对 ...
- 修改 jquery.validate.js 支持非form标签
尝试使用markdown来写一篇blog,啦啦啦 源代码传送门:github 在特殊情况下我们使用jquery.validate.js对用户输入的内容做验证的时候,表单并不是一定包含在form之中,有 ...
- 上传图片HTML <form> 标签的 method 属性
<!DOCTYPE HTML><html><body> <form action="/example/html5/demo_form.asp&quo ...
- 关于form标签,你该知道
有没有发现,自己在写模板的时候很少使用form元素,一来form和table总是那么傻傻分不清楚:二来form的特性理解不清楚,有了input.label来了直接就上,根本不用form(不知道有没有人 ...
- 解决HtmlAgilityPack无法获取form标签子节点的问题
问题描述 今天使用HtmlAgilityPack提取Form表单下的input节点,发现提取的form节点没有子节点,InnerHtml也是为空,起初以为是标签不全导致,后来分析html代码发现不可能 ...
随机推荐
- Response.End()在Webform和ASP.NET MVC下的表现差异
前几天在博问中看到一个问题--Response.End()后,是否停止执行?MVC与WebForm不一致.看到LZ的描述后,虽然奇怪于为何用Response.End()而不用return方式去控制流程 ...
- union (共用声明和共用一变量定义)
"联合"是一种特殊的类,也是一种构造类型的数据结构.在一个"联合"内可以定义多种不同的数据类型, 一个被说明为该"联合"类型的变量中,允许装 ...
- mac下使用brew安装ffmpeg支持x265
使用brew install ffmpeg 安装ffmpeg默认是没有支持x265的, 使用brew info ffmpeg 获取安装选项帮助, 使用brew reinstall ffmpeg --w ...
- Laravel 流程分析——整体概论
从整体上来看(不考虑细节),Laravel流程相当简单,我们分析一下index.php文件(下面的第几行为实际代码,不是指文件的行) 第一行定义自动加载 require __DIR__.'/../bo ...
- c/c++ 软件集成 安装和可卸载软件
作为一个工程师应具备的一些能力: 1. 首先具备这款软件: >inno Setup 免费版还开源,良心货,妥妥的. 2. 这款软件上手也比较款,可自行参考使用文档 3.编译成功,生 ...
- 51nod 1135 原根
题目链接:51nod 1135 原根 设 m 是正整数,a是整数,若a模m的阶等于φ(m),则称 a 为 模m的一个原根.(其中φ(m)表示m的欧拉函数) 阶:gcd(a,m)=1,使得成立的最小的 ...
- 初识selendroid
Testerhome社区的lihuazhang对selendroid官网的部分内容进行了翻译和讲解. 以下内容均摘自lihuazhang.感谢lihuazhang的讲解.原文地址:https://gi ...
- 1-5Tomcat 目录结构 和 web项目目录结构
对应我的安装路径: web项目目录结构
- 常用的工具cmd命令
1.stikynot 2.psr 3.cmd 4.calc 5.mspaint 6.ping
- android 高效加载大图
在写代码的时候就已经解释: /** * 计算samplesize的大小 * @param options 传一个BitmapFactory.Options 进去获取图片的大小和类型 * @param ...