All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.iartisan.runtime.utils.BeanUtil Maven / Gradle / Ivy

The newest version!
package org.iartisan.runtime.utils;

import org.iartisan.runtime.bean.PageWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 

* Bean Utils * * @author King * @since 2017/7/7 */ public class BeanUtil { private static Logger logger = LoggerFactory.getLogger(BeanUtil.class); public static T copyBean(Object resource, Class clazz) { try { if (null == resource) { return null; } T result = clazz.newInstance(); BeanUtils.copyProperties(resource, result); return result; } catch (InstantiationException e) { e.printStackTrace(); logger.error("copyBean InstantiationException:" + e); } catch (IllegalAccessException e) { e.printStackTrace(); logger.error("copyBean IllegalAccessException:" + e); } return null; } public static List copyList(List resource, Class clazz) { if (null == resource) { return null; } List result = new ArrayList<>(); for (Object o : resource) { T t = copyBean(o, clazz); result.add(t); } return result; } public static PageWrapper copyPage(PageWrapper resource, Class clazz) { if (null == resource) { return null; } PageWrapper resPage = new PageWrapper<>(resource.getPage()); List dataList = BeanUtil.copyList(resource.getRows(), clazz); resPage.setRows(dataList); return resPage; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy