-----------------------------------------------------------------------------------

<%@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标签的使用的更多相关文章

  1. springmvc的form标签

    1.要使用Spring MVC提供的表单标签,首先需要在视图页面添加: <%@ taglib prefix="form" uri="http://www.sprin ...

  2. springMvc <form:form>标签 <form:input>标签需要注意的问题

    在用springMVC <form:form>表单时,喜欢报的错误如下所示: 错误的Controller层的代码如下: @RequestMapping(value = "test ...

  3. SpringMVC form 表单提交报400错误

    错误代码: HTTP Status 400 - type Status report message description The request sent by the client was sy ...

  4. 如何用Spring框架的<form:form>标签实现REST风格的增删改查操作

    1.首先创建两个bean类,Employee(职工)和Department(部门),一个部门可以有多个职工 Employee类(属性:职工ID:id:姓名:lastName:邮箱:email:性别:g ...

  5. s:form标签

    2017-01-07 17:43:18 基本的用法 <!-- Action类必须有一个无参的构造器,因为在执行action方法之前,拦截器已经创建了一个"空"的Action对 ...

  6. 修改 jquery.validate.js 支持非form标签

    尝试使用markdown来写一篇blog,啦啦啦 源代码传送门:github 在特殊情况下我们使用jquery.validate.js对用户输入的内容做验证的时候,表单并不是一定包含在form之中,有 ...

  7. 上传图片HTML <form> 标签的 method 属性

    <!DOCTYPE HTML><html><body> <form action="/example/html5/demo_form.asp&quo ...

  8. 关于form标签,你该知道

    有没有发现,自己在写模板的时候很少使用form元素,一来form和table总是那么傻傻分不清楚:二来form的特性理解不清楚,有了input.label来了直接就上,根本不用form(不知道有没有人 ...

  9. 解决HtmlAgilityPack无法获取form标签子节点的问题

    问题描述 今天使用HtmlAgilityPack提取Form表单下的input节点,发现提取的form节点没有子节点,InnerHtml也是为空,起初以为是标签不全导致,后来分析html代码发现不可能 ...

随机推荐

  1. BBC.万物与虚无.Everything.and.Nothing

    这么有意思的纪录片怎么能错过 待续~

  2. @Scheduled 注解

    Spring配置文件xmlns加入 <!---加入:xmlns:task="http://www.springframework.org/schema/task"--> ...

  3. jquery导航栏

    html <ul class="list"> <li>下拉菜单 <ul class="nav"> <li>下拉菜 ...

  4. Nginx reopen reload作用及工作过程

    http://www.iigrowing.cn/nginx-reopen-reload-zuo-yong-ji-gong-zuo-guo-cheng.html Nginx reopen reload作 ...

  5. android 中theme样式的解释

    android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式 android:theme="@androi ...

  6. 给一个div绝对定位后,如何让它水平居中

    <style> .footer{position:absolute;left:0;right:0} </style> <div classs="footer&q ...

  7. WCF初探-22:WCF中使用Message类(上)

    前言 从我们学习WCF以来,就一直强调WCF是基于消息的通信机制.但是由于WCF给我们做了高级封装,以至于我们在使用WCF的时候很少了解到消息的内部机制.由于WCF的架构的可扩展性,针对一些特殊情况, ...

  8. bzoj 2768: [JLOI2010]冠军调查

    #include<cstdio> #include<iostream> #define M 100000 #include<cstring> using names ...

  9. hdu 1047 (big integer sum, fgets or scanf, make you func return useful infos) 分类: hdoj 2015-06-18 08:21 39人阅读 评论(0) 收藏

    errors made, boundary conditions, <= vs < , decreasing vs increasing , ++, –, '0'/'1' vs 0/1 p ...

  10. fifo read

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types. ...