com.codingapi.springboot.framework.convert.BeanConvertor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of springboot-starter Show documentation
Show all versions of springboot-starter Show documentation
springboot-starter project for Spring Boot
The newest version!
package com.codingapi.springboot.framework.convert;
import org.springframework.beans.BeanUtils;
import java.lang.reflect.InvocationTargetException;
public class BeanConvertor {
public static T convert(S source, Class clazz) {
if (source == null) {
return null;
}
T target = null;
try {
target = clazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
return null;
}
BeanUtils.copyProperties(source, target);
return target;
}
}