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代码发现不可能 ...
随机推荐
- HTTP中的摘要认证机制
引子: 指定和服务器端交互的HTTP方法,URL地址,即其他请求信息: Method:表示http请求方法,一般使用"GET","POST". url:表示请求 ...
- tomcat下iims的配置感悟
1.没有想(意识)到清楚:resin下的web.xml 和tomcat下的web.xml是不同的. 2.对于connect读取配置文件以及连接数据库根本就没有意识. /** * 获取本系统DB配置的文 ...
- 【转载】jQuery1.5之后的deferred对象详解
原文:http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html 原文作者 ...
- [java基础]循环结构1
[java基础]循环结构1 循环结构:for循环,while循环,do_while循环在,增强型for循环 /** 文件路径:G:\JavaByHands\循环语句\ 文件名称:WhileTest.j ...
- android,NDK android.mk相关
1.c++ try...catch的支持 需要在Android.mk 中添加 LOCAL_CPPFLAGS += -fexceptions,或者在Application.mk中添加APP_CPPFLA ...
- windows防火墙命令详解
Old command 针对win7以下版本<包含win7> Example 1: 启用一个程序 Old command New command netsh firewall add al ...
- Echarts的基本用法
首先需要到导入echatrs.js文件 <script src="dist/echarts.js"></script> 路径配置 require.confi ...
- [转]为什么不能用memcached存储Session
以下内容转自:http://www.infoq.com/cn/news/2015/01/memcached-store-session -------------------------分割线---- ...
- NGINX location 在配置中的优先级
location表达式类型 ~ 表示执行一个正则匹配,区分大小写 ~* 表示执行一个正则匹配,不区分大小写 ^~ 表示普通字符匹配.使用前缀匹配.如果匹配成功,则不再匹配其他location. = 进 ...
- spirng线程池的配置与使用
1.在xml中配置线程池 <!-- 配置线程池 --> <bean id="taskExecutor" class="org.springframewo ...