17SpringMvc_在业务控制方法中写入包装User的模型来收集参数——解决问题
在解决问题之前,我要说明一下jsp页面上填入信息,一个用户的信息比如用户的名字,用户的电话,用户的手机等等,在这个jsp页面上填好信息后,转到有个action处理这个信息。原理是什么?
在jsp页面上有一行代码,form action="${pageContext.request.contextPath}/user/register.action"那么jsp页面提交的时候机会提交到这个action。然后根据这个定位到
public String registerMethod(Bean bean,Model model),这里有一个参数,bean。
bean里面又封装了user类和admin类。所以user和admin才是里面的基础元素。 jsp上面的页面就会根据这个bean的结构,把jsp的内容自动写入到这个bean中。但是切记<input type="text" name="admin.username"
这里的name要和实体类的名字一模一样,这里的admin就是bean里面的一个属性username是admin里面的属性。
-------------------------------------------------------------------------------------------------------------------------------------------------------------
前一篇文章,讲了在业务方法中多个模型收集参数有一个问题,现在这篇文章就来解决一上一篇文章的问题。
User和Admin是两个不同的实体类。我们解决问题的方法是:
如果多个模型中有相同的属性时,可以用user.username或admin.username来收集客户端参数。就是用一个新的模型将User和Admin再封装一次。
给出案例的结构图:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUUAAAGXCAIAAACr4NUuAAAgAElEQVR4nO2de3Qb1b3vxR/97/zBWnQtzv3jrracEtJmXSgh6bnVoZQ+7g1tz7pl0RqSniak9FYXSlvCoyUGAnYSpz4mKQMkJCGQOAds1GBDwEQkTZ0HkPiRkNh5KhaOLduJbVly5Lcc29n3j5Fm9szsGY1kzWhm6/tZe2VJoz0POf74t2c0+ysPAQBYSSKR6O7u7u3tjcViVyji8bj4r8TQ0NDw8HAkEpHWXfr7Z/d8fvnAucHWPkK3PZ9f3lxVR+9CxJOPNwhAAQGfAeAH+Jw9j995Y74PIaeEBK/HK4RyuMWAL8cbzITcvx0XAJ8z4ODq2w8/8z+k9mrRV+inB1ffnu8DnB1O9zkkeD0eXyCT7lntPSR4PUnM780hwOcMOPz0vNDB7Zeadl5q2nni3Re3r1hMPz389Lx8H6DTyKnPIcHr9XrTKBYS0vVIR8AnaezCCg+fk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Y14ixvF7UsPkj01G2QfXjd8diHw2Yi1Ne1dgyRctzJ2aHkiWHLqzbsSwZLYweVddSv18sPO9Gpb6OkFnqIq5kt2taPCtzy+zexX2YfXNQif3Qd8NmJtTXvnIAlXFc1cXB375Kl753pinzw10746XFWklx926rK2hf68wPOLt5kv2dQ+KvV6FggfsV9lH14nfHYh8NmItTXtHYPkaNmt17pfiweFPRvviwcF0vXa0bJb9fLDWi9rW1IY1kvWt7eT6WKbdPuwD68DPrsQ+GzEX+s6g33Tlxoqj5bdSrdLDZV6+WEtl3hopy+TYN/0X+s67f+Zg9kAn434+MTA7mOxUGRG50YRblsoMrP7WGzP58gzcBnw2YjJqZm6Y5GK3RfzHgBkc6vYfbHuWGRyaibf/wMgM+AzAPwAnwHgB/gMAD/AZwD4wfU+V1eslpoV25cx/Ma3fKL7ze+g4HC3z9vXlU13t0x3t8x0fjb18bYtTzyZ813IcOWz9BXRyjUDPnw9tKtR+Tw8PDzGYmRkxEE+v/J8xSslFa88X/HnA+O/ez/+H9sH/v0/u7/7dPvC3194paRC0Z6vyNVOnUvGPlN/mQK+lL8hwevxeH0+fBOlm1H5PDY29q1vfevmm2+++eab586de+edd/p8vvXr14+NjTnI5+/9YlfZ3y590D7zQXhmd8e1D8Iz2rb74kzZy43f+8WuXO3UuWTqs+LbY1VfJYtvlnU3zPpcVFT04IMPFhcXV1VVHTx4MFf1+f8D4rPHWgANtsMAAAAASUVORK5CYII=" alt="" />
上面结构图中用到了Admin.java;Bean.java;UserAction.java;springmvc_008.xml;spring.xml;web.xml;person.xml;
下面给出具体的案例代码:我只给出person.jsp的代码以及UserAction(控制器).java。
person.jsp:注意:<input type="text" name="user.username" value="${user.username }" /></td>
value="${user.username }是为了回显数据,不写也没事。
name的写法都是这么写的。因为bean把uesr和admin又包了一层,相当于user.name和admin.name才是最基础的元素。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<hr>
普通用户
<form action="${pageContext.request.contextPath}/user/register.action" method="post">
<table border="2" align="center">
<tr>
<th>姓名</th>
<td> <input type="text" name="user.username" value="${user.username }" /></td>
</tr>
<tr>
<th>薪水</th>
<td> <input type="text"
name="user.salary"
value="${!empty user.salary?user.salary:'2012'}" /> </td>
</tr>
<tr>
<th>入职时间</th>
<!--
${!empty user.hiredate?user.hiredate:'2015-4-3 12:12:12'}
表示user.hiredate不是为空的话就给他赋user.hiredate的值
如果是空的就给他赋'2015-4-3 12:12:12'这个值。
-->
<td> <input
type="text"
name="user.hiredate" value="${!empty user.hiredate?user.hiredate:'2015-4-3 12:12:12'} "/></td>
</tr> <tr>
<td>
<input type="submit" value="普通用户注册">
</td>
</tr>
</table> </form>
</hr> <hr>
管理员用户
<form action="${pageContext.request.contextPath}/user/register.action" method="post">
<table border="2" align="center">
<tr>
<th>姓名</th>
<td> <input type="text" name="admin.username" value="${admin.username }" /></td>
</tr> <tr>
<th>薪水</th>
<td> <input type="text"
name="admin.salary"
value="${admin.salary }" />
</td>
</tr>
<tr>
<th>入职时间</th>
<!--
${!empty user.hiredate?user.hiredate:'2015-4-3 12:12:12'}
表示user.hiredate不是为空的话就给他赋user.hiredate的值
如果是空的就给他赋'2015-4-3 12:12:12'这个值。
-->
<td> <input
type="text"
name="admin.hiredate" value="${admin.hiredate }"/></td>
</tr> <tr>
<td>
<input type="submit" value="管理员注册">
</td>
</tr>
</table>
</form>
</hr>
</body>
</html>
UserAction.java的代码:
package com.guigu.shen.Action8; import java.text.SimpleDateFormat;
import java.util.Date; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
*
*
请求路径可以拆分为:根模块的名字+分模块的名字
就是相当于当访问http://127.0.0.1:8080:项目名/user/register时就会进入到
registerMethod方法。
*/
@Controller
@RequestMapping(value="/user")//根模块的请求名字
public class UserAction {
/*
* 员工注册
*
*/
@RequestMapping(method=RequestMethod.POST,value="/register")//分模块的请求名字
/*
采用模型的方式(User)来收集从页面传来的参数。
方法里面的参数user和以前的参数一样会被用反射的方式去赋值。
bean类把User和Admin又封装了一层。
*/
public String registerMethod(Bean bean,Model model)
{
//打印出user里面的信息
System.out.println("员工的信息是"+bean.getUser());
//打印出Admin的信息
System.out.println("管理员的信息"+bean.getAdmin());
//将user和admin绑定到model对象中去。
model.addAttribute("user", bean.getUser());
model.addAttribute("admin", bean.getAdmin());
//model.addAttribute("bean", bean);
//数据回显到person.jsp页面
return "/person.jsp";
} /**
* 自定义类型转换器
* 就是说当Date类型的数据不能得到时,会自动查找@InitBinder注解过的方法
*
*/
@InitBinder
protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
} }
bean类代码:
package com.guigu.shen.Action8; public class Bean {
private User user;
private Admin admin;
/**
* @return the user
*/
public User getUser() {
return user;
}
/**
* @param user the user to set
*/
public void setUser(User user) {
this.user = user;
}
/**
* @return the admin
*/
public Admin getAdmin() {
return admin;
}
/**
* @param admin the admin to set
*/
public void setAdmin(Admin admin) {
this.admin = admin;
} }
结果:测试一切正常。
17SpringMvc_在业务控制方法中写入包装User的模型来收集参数——解决问题的更多相关文章
- 在业务控制方法中写入包装User的模型来收集参数
可以在业务控制方法中书写0个或多个模型来收集客户端的参数 1) 如果多个模型中有相同的属性时,可以用user.name或admin.name来收集客户端参数 2) 用一个新的模型将User和Adm ...
- 在业务控制方法中写入Request,Response等传统web参数
可以在业务控制方法中书写传统web参数,这种方式我们不提倡,耦合了 @Controller @RequestMapping(value="/user") public class ...
- 14SpringMvc_在业务控制方法中写入HttpServletRequest,HttpServletResponse等传统web参数(这个知识点知道就好了,不推荐这么去做)
这篇文章解决的问题是怎么在业务方法里面引入我们熟悉的HttpServletRequest和HttpServletRespon? 答案:这种引入传统的web参数的做法不推荐去做,因为这么做会实行高度耦合 ...
- 15SpringMvc_在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型
之前第12篇文章中提到过在业务控制方法中写入普通变量收集参数的方式,也提到了这种凡方式的弊端(参数很多怎么办),所以这篇文章讲的是在业务控制方法中写入模型变量来收集参数.本文的案例实现的功能是,在注册 ...
- 在业务控制方法中写入User,Admin多个模型收集参数
1) 可以在业务控制方法中书写1个模型来收集客户端的参数 2) 模型中的属性名必须和客户端参数名一一对应 3) 这里说的模型不是Model对象,Model是向视图中封装的数据 @Controll ...
- 16SpringMvc_在业务控制方法中写入User,Admin多个模型收集参数——引出问题
上面文章时普通的业务那个方法中收集一个实体类,这篇文章想收集两个实体类. 文本要做的是:在person.jsp页面上,有两个表单.分别是普通用户和管理员用户的表单(普通用户的表单和管理员用户的表单里面 ...
- 12SpringMvc_在业务控制方法中写入普通变量收集参数
这篇文章讲的是jsp页面不是会传一些参数到Action中,那么Action怎么去接受这个数据呢? 方案: 案例结构如下:
- 在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型
1) 在默认情况下,springmvc不能将String类型转成java.util.Date类型,所有我们只能在Action 中自定义类型转换器 <form action="${pa ...
- 19SpringMvc_在业务控制方法中收集List集合中包含JavaBean参数
本文要实现的功能是给一张表单:
随机推荐
- Threading.Tasks 简单的使用
using Lemon.Common; using System; using System.Collections.Generic; using System.Linq; using System. ...
- CRM Home Grid StyleSet
用户进行到记录列表后,虽然可以通过视图来区分不同条件的记录但是不能重点突出记录的重要性.我们根据客户的需求特别定制了如下解决方案,比如根据记录的状态,字段值 在列表面上把行的背景显示成不同的着色来突出 ...
- android内存泄露调试,Heap,MAT
三.内存监测工具 DDMS --> Heap 无论怎么小心,想完全避免bad code是不可能的,此时就需要一些工具来帮助我们检查代码中是否存在会造成内存泄漏的地方.Android tools中 ...
- 【读书笔记】iOS-NSDictionary与NSArray的比较
有时候为什么不用数组存储然后在数组里查询数值呢?字典(也称为散列表或关联数组)使用的是键查询的优化存储方式.它可以立即找出要查询的数据,而不需要遍历整个数组进行查找.对于频繁的查询和大型的数据集来说, ...
- IOS 杂笔-3 (property参数)
(1)内存管理相关参数 Retain:对对象release旧值,retain新值(适用于OC对象类型) Assign:直接赋值(默认,适用于非oc对象类型) Copy:release旧值,copy新值 ...
- iOS9 HTTP 不能正常使用的解决办法
Google后查证,iOS9引入了新特性App Transport Security (ATS).详情:App Transport Security (ATS) 新特性要求App内访问的网络必须使用H ...
- iOS开发笔记6:图片轮播及其无限循环效果
平时APP中的广告位或者滚动的新闻图片等用到的就是图片轮播这种效果,实现方式主要有两种,一种是ScrollView+ImageView,另一种则是通过CollectionView,今天总结的是Scro ...
- ios appIcon配置
iOS 我所知道的Assets.xcassets 字数923 阅读723 评论1 喜欢3 Assets.xcassets是用来存放图像资源文件的.将一个图片放在Assets里面是这个样子的 目录结构 ...
- centos到底下载哪个版本?
CentOS-7.0-1406-x86_64-DVD.iso 标准安装版,一般下载这个就可以了CentOS-7.0-1406-x86_64-NetInstall.iso ...
- python sorted用法
python列表排序 python字典排序 sorted List的元素可以是各种东西,字符串,字典,自己定义的类等. sorted函数用法如下: sorted(data, cmp=None, key ...