把表单的数据封装到Bean中
来源:互联网 发布:软件使用统计表 编辑:程序博客网 时间:2024/04/29 10:09
1、实际开发中,通常把表单数据封装到Bean中
需要导入两个Jar包:commons-beanutils-1.8.3.jar包;commons-logging-1.1.1.jar包
public static <T> T request2Bean(HttpServletRequest request,Class <T> beanClass){
try {
//创建要封装数据的bean
T bean = beanClass.newInstance();
//把request的数据整合到bean中
Enumeration e=request.getParameterNames();
while(e.hasMoreElements()){
//拿到表单中参数的名字,在表单中,name的值一定要与Bean的字段一样
String name=(String)e.nextElement();
String value=request.getParameter(name);//username password
BeanUtils.setProperty(bean, name, value);//zhangsan 123456
}
return bean;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
2、通过封装到Bean中,在检测数据合法性
RegisterForm form=request2Bean(request,RegisterForm.class);//封装到了form里
通过form调用检测数据的方法验证数据合法性
- 把表单的数据封装到Bean中
- 把表单的数据封装到JavaBean中
- 第八天2月28日,把表单的数据封装到JavaBean中,通过request对象,有多种方式
- 定义一个JavaBean,把数据封装到bean里
- struts2中怎么把表单数据封装到实体类里
- 将表单提交的数据封装到T中
- 自动表单数据封装到javaBean中
- 表单数据自动封装到javaBean中
- struts1.x中不用FormBean,如何快速把页面表单的数据放入实体bean中
- struts2中基于表单数据的封装
- BeanUtils主要解决 的问题: 把对象的属性数据封装 到对象中
- BeanUtils主要解决 的问题: 把对象的属性数据封装 到对象中
- 把request对象中的请求参数封装到bean中/生成UUID
- JS 表单数据封装到后台的工具类
- springmvc中异步发送表单数据到Bean,并响应JSON文本返回
- 表单验证封装集成到项目中
- Spring注入Date类型的数据到Bean中
- 03-32位UUID和封装Map对象到指定类型的Bean中
- Matlab程序 转C++/Opencv 不可不知的17个函数
- Java经典题目
- 页面分页技术(一)-------------完全利用JSP进行分页
- xmanager
- PostgreSQL直接查询CSV文件的方法:file_fdw
- 把表单的数据封装到Bean中
- android电话拦截及短信过滤
- 使用convert制制作gif图片动画
- geoserver 版本比较和数据的移植
- javascript WebFXTree
- Spring中应用java动态代码实现Aop
- /usr/X11R6/bin/xauth: timeout in locking authority file /home/oracle/.Xauthority
- RAC-配置及其错误信息整理
- result codes returned by the various SQLite functions