当前位置: 首页 > news >正文

铜陵专业网站制作公司什么是软文营销?

铜陵专业网站制作公司,什么是软文营销?,WordPress登录不进,自己用模板做网站工具类|将Entity对象转为Vo/Bo对象#xff0c;并指定字段绑定 实体类#xff1a;People和Student,Student的三个字段和People意义一样#xff0c;但是字段名不完全一样#xff0c;要实现对象拷贝可使用如下工具类#xff0c;用到了反射。 People.java Data AllArgsConst…工具类|将Entity对象转为Vo/Bo对象并指定字段绑定 实体类People和Student,Student的三个字段和People意义一样但是字段名不完全一样要实现对象拷贝可使用如下工具类用到了反射。 People.java Data AllArgsConstructor NoArgsConstructor public class People {private Integer id;private String name;private Integer age;private String sex;private String classNum;private String health;private String height;private String weight; }Student.java Data AllArgsConstructor NoArgsConstructor public class Student {private Integer stuId;private String stuName;private Integer age; }CommonBeanUtils.java package cn.yto.hbd.utils;import lombok.extern.slf4j.Slf4j; import org.springframework.beans.*; import org.springframework.util.*; import javax.xml.datatype.XMLGregorianCalendar; import java.beans.PropertyDescriptor; import java.lang.reflect.*; import java.util.*;/*** Description: Bean对象转化Vo对象工具类*/ Slf4j public abstract class CommonBeanUtils extends org.springframework.beans.BeanUtils {/*** 对象赋值:将source对象与target对象按照匹配的字段一对一复制** param source 源Entity* param target 目标Vo对象* throws BeansException*/public static void copyProps(Object source, Object target) throws BeansException {Assert.notNull(source, Source must not be null);Assert.notNull(target, Target must not be null);Class? actualEditable target.getClass();PropertyDescriptor[] targetPds getPropertyDescriptors(actualEditable);for (PropertyDescriptor targetPd : targetPds) {if (targetPd.getWriteMethod() ! null) {PropertyDescriptor sourcePd getPropertyDescriptor(source.getClass(), targetPd.getName());if (sourcePd ! null sourcePd.getReadMethod() ! null) {try {Method readMethod sourcePd.getReadMethod();if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {readMethod.setAccessible(true);}Object value readMethod.invoke(source);// 这里判断以下value是否为空 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等if (value ! null) {Method writeMethod targetPd.getWriteMethod();Type targetParameterType writeMethod.getGenericParameterTypes()[0];// 特殊类型不再执行copy XMLGregorianCalendarif (!(targetParameterType.equals(XMLGregorianCalendar.class))) {if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {writeMethod.setAccessible(true);}writeMethod.invoke(target, value);}}} catch (Throwable ex) {log.error(ex.getMessage());throw new FatalBeanException(Could not copy properties from source to target, ex);}}}}}/*** 对象赋值:将source对象与target按照匹配的字段一一复制** param source 源Entity* param target 目标Vo对象* param props 对应字段0或多个* throws BeansException*/public static void copyProps(Object source, Object target, final String... props) throws BeansException {Assert.notNull(source, Source must not be null);Assert.notNull(target, Target must not be null);Class? actualEditable target.getClass();PropertyDescriptor[] targetPds getPropertyDescriptors(actualEditable);for (PropertyDescriptor targetPd : targetPds) {if (targetPd.getWriteMethod() ! null) {String prop_1;String prop_2;String targetPdNameTemp ;for (int i 0; i props.length; i) {String[] params props[i].split();prop_1 params[0];prop_2 params[1];if (Objects.equals(targetPd.getName(), prop_1)) {targetPdNameTemp prop_2;break;}if (Objects.equals(targetPd.getName(), prop_2)) {targetPdNameTemp prop_1;break;}}//1.将字段转换实现字段绑定PropertyDescriptor sourcePd;//指定了的字段绑定的按绑定字段赋值if (!.equals(targetPdNameTemp) null ! targetPdNameTemp) {sourcePd getPropertyDescriptor(source.getClass(), targetPdNameTemp);} else {//没有指定字段的自动匹配字段名sourcePd getPropertyDescriptor(source.getClass(), targetPd.getName());}if (sourcePd ! null sourcePd.getReadMethod() ! null) {try {Method readMethod sourcePd.getReadMethod();if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {readMethod.setAccessible(true);}Object value readMethod.invoke(source);// 这里判断以下value是否为空 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等if (value ! null) {Method writeMethod targetPd.getWriteMethod();Type targetParameterType writeMethod.getGenericParameterTypes()[0];// 特殊类型不再执行copy XMLGregorianCalendarif (!(targetParameterType.equals(XMLGregorianCalendar.class))) {if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {writeMethod.setAccessible(true);}writeMethod.invoke(target, value);}}} catch (Throwable ex) {log.error(ex.getMessage());throw new FatalBeanException(Could not copy properties from source to target, ex);}}}}}/*** 集合对象转化赋值如ListPeople 转为ListStudent实体Student的字段是People字段的子集** param sources 源集合对象* param voClass vo类型* param T* return*/public static T ListT copyListProps(List? extends Object sources, final ClassT voClass) {Assert.isTrue(!CollectionUtils.isEmpty(sources), Source must not be null);ListT targets new ArrayList();sources.forEach(source - {try {T target voClass.newInstance();copyProperties(source, target);targets.add(target);} catch (InstantiationException | IllegalAccessException e) {log.error(e.getMessage());}});return targets;}/*** 集合对象转化赋值如ListPeople 转为ListStudent实体Student的字段是People字段的子集** param sources 源Entity集合对象* param voClass vo类型.class* param T* return*/public static T ListT copyListProps(List? extends Object sources, final ClassT voClass, final String... props) {Assert.isTrue(!CollectionUtils.isEmpty(sources), Source must not be null);ListT targets new ArrayList();sources.forEach(source - {try {T target voClass.newInstance();//调用带参数绑定的拷贝方法copyProps(source, target, props);targets.add(target);} catch (InstantiationException | IllegalAccessException e) {log.error(e.getMessage());}});return targets;} }测试类 package cn.yto.hbd.utils;public class Test0 {public static void main(String[] args) {People people new People();Student student new Student();people.setId(4);people.setAge(10);people.setName(张三 );people.setClassNum(3);people.setHealth(健康000);people.setHeight(180cm);people.setWeight(60kg);people.setSex(男);CommonBeanUtils.copyProps(people,student,stuIdid,namestuName);System.out.println(people);System.out.println(student);} }运行结果 运行结果 package cn.yto.hbd.utils;import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map;public class BeanConvertUtils {/*** 普通转换* param source 源* param targetClass* param T* return*/public static T T copy(Object source,ClassT targetClass){return copy(source ,targetClass,null);}/*** 普通转换* param sourceObj 源* param targetObj 目标* param T* return*/public static T T copy(Object sourceObj,T targetObj){return copy(sourceObj ,targetObj,null);}/*** 普通转换* param source 源* param targetClass* param keyMap 源字段目标字段* return*/public static T T copy(Object source,ClassT targetClass,String ...keyMap){T targetObj null;try {targetObj targetClass.getConstructor(null).newInstance(null);} catch (Exception e) {throw new RuntimeException(e);}return copy(source,targetObj,keyMap);}/*** 普通转换* param sourceObj 源* param targetObj 目标* param keyMap 源字段目标字段* return*/public static T T copy(Object sourceObj,T targetObj,String ...keyMap){Class? sourceClass sourceObj.getClass();Class? targetClass targetObj.getClass();MapString, String keyMaps new HashMap();if (keyMap!nullkeyMap.length0){for (String keyItem : keyMap) {String[] split keyItem.split();keyMaps.put(split[0],split[1]);}}Field[] sourceFieldFields sourceObj.getClass().getDeclaredFields();for (Field sourceField : sourceFieldFields) {String sourceFieldName sourceField.getName();String targetFieldNamekeyMaps.getOrDefault(sourceFieldName,sourceFieldName);String sourceMethodName getGetMethodName(sourceFieldName);String targetMethodName getSetMethodName(targetFieldName);try {Method sourceGetMethod sourceClass.getDeclaredMethod(sourceMethodName);Method targetSetField targetClass.getDeclaredMethod(targetMethodName,sourceField.getType());Object value sourceGetMethod.invoke(sourceObj);targetSetField.invoke(targetObj,value);} catch (Exception e) {//找不到字段}}return targetObj;}/*** 首字母大写* param str* return*/private static String strFirstUpper(String str){return str.substring(0,1).toUpperCase()str.substring(1);}/*** 获取get方法名* param fieldName* return*/private static String getGetMethodName(String fieldName){return getstrFirstUpper(fieldName);}private static String getSetMethodName(String fieldName){return setstrFirstUpper(fieldName);} }
http://www.zqtcl.cn/news/462765/

相关文章:

  • 建设网站对企业有什么好处wordpress教程视频下载
  • 郑州网站提升排名上海 企业 网站建设
  • 南昌好的做网站的公司营销型网站 案例
  • 南宁经典网站建设网络运维工程师是干什么的
  • 网站开发算法建网站难不难
  • 茂名模板建站定制网站开发 ide
  • 做网站现在用什么语言网站估价
  • wap开头的网站外贸网站建设官网
  • 做网站说什么5.0啥意思wordpress教程视频 下载
  • 业务型网站做seo郑州网站推广优化
  • 400网站建设南昌网站建设方案详细版
  • 网站评论回复如何做中国住建部和城乡建设官网
  • 怎么建设网站南京做南京华美整容网站
  • 有哪些可以做1元夺宝的网站推广网站哪家做的好
  • 网站备案 域名不是自己的成都电子商务网站
  • 网站内容管理系统建设2021年建站赚钱
  • 网站建设交流发言稿找做网站的上什么app
  • 企业如何应用网站的wordpress lensnews
  • 可信的邢台做网站学电商运营需要多少钱
  • 网站中文名称做微商进哪个网站安全
  • 网站前端建设需要学会什么意思wordpress 快递查询 插件
  • 网站建设腾讯云与阿里云做网站上市的公司
  • 视频直播网站app开发网站备案主体是
  • 做的好的微信商城网站建设商务网站
  • 小白用网站建设工具专做奢侈品品牌的网站
  • 安装vs2015网站开发外包公司为什么没人去
  • 网站关键字多少合适唐河微网站开发
  • 临沂网站建站专业公司网站开发 文学
  • 乐清网站建设服务定制企业网站建设
  • 简单公司网站模版百度站长工具抓取诊断