package com.fengdu.utils;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.PropertyUtilsBean;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
/**
* bean 对象工具类
* 描述:<br>
*
* @author 李鹏军
* @version 1.0
* @since 1.0.0
*/
public class MyBeanUtils extends PropertyUtilsBean {
/**
* 主要功能:转换
* 注意事项:无
*
* @param dest 结果对象
* @param orig 来源对象
* @throws IllegalAccessException 异常
* @throws InvocationTargetException 异常
*/
@SuppressWarnings("all")
private static void convert(Object dest, Object orig)
throws IllegalAccessException,
InvocationTargetException {
// Validate existence of the specified beans
if (dest == null) {
throw new IllegalArgumentException("No destination bean specified");
}
if (orig == null) {
throw new IllegalArgumentException("No origin bean specified");
}
// Copy the properties, converting as necessary
if (orig instanceof DynaBean) {
DynaProperty[] origDescriptors = ((DynaBean) orig).getDynaClass().getDynaProperties();
for (int i = 0; i < origDescriptors.length; i++) {
String name = origDescriptors[i].getName();
if (PropertyUtils.isWriteable(dest, name)) {
Object value = ((DynaBean) orig).get(name);
try {
getInstance().setSimpleProperty(dest, name, value);
} catch (Exception e) {
; // Should not happen
}
}
}
} else if (orig instanceof Map) {
Iterator names = ((Map) orig).keySet().iterator();
while (names.hasNext()) {
String name = (String) names.next();
if (PropertyUtils.isWriteable(dest, name)) {
Object value = ((Map) orig).get(name);
try {
getInstance().setSimpleProperty(dest, name, value);
} catch (Exception e) {
; // Should not happen
}
}
}
} else { /* if (orig is a standard JavaBean) */
PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(
orig);
for (int i = 0; i < origDescriptors.length; i++) {
String name = origDescriptors[i].getName();
// String type = origDescriptors[i].getPropertyType().toString();
if ("class".equals(name)) {
continue; // No point in trying to set an object's class
}
if (PropertyUtils.isReadable(orig, name)
&& PropertyUtils.isWriteable(dest, name)) {
try {
Object value = PropertyUtils.getSimpleProperty(orig,
name);
getInstance().setSimpleProperty(dest, name, value);
} catch (IllegalArgumentException ie) {
; // Should not happen
} catch (Exception e) {
; // Should not happen
}
}
}
}
}
/**
* 对象拷贝
* 数据对象空值不拷贝到目标对象
*
* @param databean 数据对象
* @param tobean 返回对象
* @throws Exception 异常
*/
public static void copyBeanNotNull2Bean(Object databean, Object tobean)
throws Exception {
PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(
databean);
for (int i = 0; i < origDescriptors.length; i++) {
String name = origDescriptors[i].getName();
// String type = origDescriptors[i].getPropertyType().toString();
if ("class".equals(name)) {
continue; // No point in trying to set an object's class
}
if (PropertyUtils.isReadable(databean, name)
&& PropertyUtils.isWriteable(tobean, name)) {
try {
Object value = PropertyUtils.getSimpleProperty(databean,
name);
if (value != null) {
getInstance().setSimpleProperty(tobean, name, value);
}
} catch (IllegalArgumentException ie) {
; // Should not happen
} catch (Exception e) {
; // Should not happen
}
}
}
}
/**
* 把orig和dest相同属性的value复制到dest中
*
* @param dest 结果
* @param orig 来源
* @throws Exception 异常
*/
public static void copyBean2Bean(Object dest, Object orig)
throws Exception {
convert(dest, orig);
}
/**
* 主要功能:bean 转换成 map
* 注意事项:无
*
* @param map map对象
* @param bean bean对象
*/
@SuppressWarnings("all")
public static void copyBean2Map(Map map, Object bean) {
PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean);
for (int i = 0; i < pds.length; i++) {
PropertyDescriptor pd = pds[i];
String propname = pd.getName();
try {
Object propvalue = PropertyUtils.getSimpleProperty(bean,
propname);
map.put(propname, propvalue);
} catch (IllegalAccessException e) {
// e.printStackTrace();
} catch (InvocationTargetException e) {
// e.printStackTrace();
} catch (NoSuchMethodException e) {
// e.printStackTrace();
}
}
}
/**
* 主要功能:bean 转换成 map
* 注意事项:无
*
* @param map map对象
* @param bean bean对象
*/
@SuppressWarnings("all")
public static void copyBean2Map(Map map, Object bean,
List<String> fieldNameList) {
for (int i = 0; i < fieldNameList.size(); i++) {
String oldPropname = fieldNameList.get(i);
String propname = StringUtils.lineToHump(oldPropname);
try {
Object propvalue = getProp(bean, propname);
map.put(oldPropname, propvalue);
} catch (Exception e) {
}
}
}
/**
* 将Map内的key与Bean中属性相同的内容复制到BEAN中
*
* @param bean Object
* @param properties Map
*/
@SuppressWarnings("all")
public static void copyMap2Bean(Object bean, Map properties) {
if ((bean == null) || (properties == null)) {
return;
}
// map key 集合
Iterator names = properties.keySet().iterator();
// 逐个处理key转换
while (names.hasNext()) {
String name = (String) names.next();
if (name == null) {
continue;
}
Object value = properties.get(name);
try {
// name转换成驼峰
name = StringUtils.lineToHump(name);
// 获取属性类型
Class clazz = PropertyUtils.getPropertyType(bean, name);
if (null == clazz) {
continue;
}
String className = clazz.getName(
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
项目介绍 基于Spring+SpringMVC+Mybatis+ shiro+vue+swagger2微信小程序式敏捷开发系统架构,提供整套公共微服务服务模块:内容管理、支付中心、用户管理(包括第三方)、微信平台、存储系统、配置中心、日志分析、任务和通知等,支持服务治理、监控和追踪, 努力为中小型企业打造全方位J2EE企业级开发解决方案。 3.项目组织结构描述: 输入图片说明 my-shop-manager --综合后台管理 my-shop-api --微信小程序商城api接口 my-shop-common --公共模块 my-shop-web --网站商城 my-shop-merchants --运营商管理平台 my-shop-gen --代码生成 my-shop-schedule --定时任务 my-shop-shiro --登陆权限相关 my-shop-webchat --微信管理 my-shop-oss --oss云存储管理 my-shop-pay --支付管理 my-shop-pointsmall --积分商城 my-shop-serach --搜索模块 my-s
资源推荐
资源详情
资源评论
收起资源包目录
基于Spring+SpringMVC+Mybatis+ Shiro分布式敏捷开发系统架构,提供整套公共微服务服务模块 (2000个子文件)
.babelrc 230B
iview.css 277KB
bootstrap.min.css 149KB
style.css 133KB
style.css 89KB
froala_editor.css 36KB
font-awesome.min.css 30KB
froala_editor.min.css 30KB
layui.css 27KB
font-awesome.css 26KB
common.css 24KB
font-awesome.min.css 21KB
_all.css 20KB
ui.jqgrid-bootstrap.css 18KB
ui.jqgrid.css 17KB
layer.css 14KB
_all.css 14KB
layer.css 14KB
_all.css 14KB
_all.css 12KB
royal.css 11KB
dark.css 11KB
gray.css 11KB
layer.css 11KB
layim.css 11KB
red.css 11KB
royal.min.css 10KB
gray.min.css 10KB
dark.min.css 10KB
red.min.css 10KB
laydate.css 8KB
awesome.css 8KB
linkage.css 7KB
metroStyle.css 6KB
zTreeStyle.css 6KB
laydate.css 6KB
layer.css 5KB
jquery.fancybox.css 5KB
froala_page.css 4KB
laydate.css 3KB
style.css 3KB
froala_page.min.css 3KB
layer.ext.css 3KB
demo.css 3KB
jquery.gritter.css 3KB
purple.css 2KB
yellow.css 2KB
orange.css 2KB
green.css 2KB
blue.css 2KB
grey.css 2KB
pink.css 2KB
aero.css 2KB
iconfont.css 2KB
red.css 2KB
login.css 2KB
line.css 2KB
icheck.css 2KB
orange.css 1KB
purple.css 1KB
yellow.css 1KB
purple.css 1KB
orange.css 1KB
yellow.css 1KB
green.css 1KB
green.css 1KB
blue.css 1KB
pink.css 1KB
grey.css 1KB
aero.css 1KB
main.css 1KB
blue.css 1KB
pink.css 1KB
grey.css 1KB
aero.css 1KB
red.css 1KB
red.css 1KB
minimal.css 1KB
polaris.css 1KB
square.css 1KB
purple.css 1KB
yellow.css 1KB
orange.css 1KB
green.css 1KB
grey.css 1KB
pink.css 1KB
aero.css 1KB
blue.css 1KB
futurico.css 1KB
red.css 1KB
flat.css 1KB
jquery.treegrid.css 1KB
code.css 1KB
ui.jqgrid-bootstrap-ui.css 662B
webuploader.css 515B
tiki.css 441B
tiddlywiki.css 220B
Thumbs.db 357KB
Thumbs.db 207KB
Thumbs.db 67KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
白话机器学习
- 粉丝: 8215
- 资源: 7687
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功