|
@ -228,32 +228,35 @@ public class BaseJpaService<T, R> {
|
|
|
* 将实体转换为模型。
|
|
|
*
|
|
|
* @param source
|
|
|
* @param targetCls
|
|
|
* @param target
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
public <T> T convertToModel(Object source, Class<T> targetCls) {
|
|
|
public <T> T convertToModel(Object source, Class<T> target) {
|
|
|
if (source == null) {
|
|
|
return null;
|
|
|
}
|
|
|
T target = BeanUtils.instantiate(targetCls);
|
|
|
BeanUtils.copyProperties(source, target);
|
|
|
return target;
|
|
|
T _target = BeanUtils.instantiate(target);
|
|
|
BeanUtils.copyProperties(source, _target);
|
|
|
return _target;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将实体集合转换为模型集合。
|
|
|
* @param sources
|
|
|
* @param targets
|
|
|
* @param targetCls
|
|
|
* @param target
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
public <T> List<T> convertToModels(Collection sources, List<T> targets, Class<T> targetCls){
|
|
|
sources.forEach(one -> {
|
|
|
T target = (T) BeanUtils.instantiate(targetCls);
|
|
|
BeanUtils.copyProperties(one, target);
|
|
|
targets.add(target);
|
|
|
public <T> List<T> convertToModels(Collection sources, List<T> targets, Class<T> target){
|
|
|
if (null == sources) {
|
|
|
return null;
|
|
|
}
|
|
|
sources.forEach(item -> {
|
|
|
T _target = BeanUtils.instantiate(target);
|
|
|
BeanUtils.copyProperties(item, _target);
|
|
|
targets.add(_target);
|
|
|
});
|
|
|
return targets;
|
|
|
}
|
|
@ -267,7 +270,7 @@ public class BaseJpaService<T, R> {
|
|
|
* @param length
|
|
|
* @return
|
|
|
*/
|
|
|
protected String getRandomString(int length) {
|
|
|
protected String randomString(int length) {
|
|
|
String str = "abcdefghigklmnopkrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789";
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
Random random = new Random();
|