提交 6dd2ebc8 authored 作者: 李秋林's avatar 李秋林

创建BeanUtils工具、添加返回RCode报错信息

上级 0fe5fc7a
package com.wangxiaolu.promotion.common.util;
import java.util.ArrayList;
import java.util.List;
/**
* @author : liqiulin
* @date : 2025-02-07 10
* @describe :
*/
public class BeanUtils extends org.springframework.beans.BeanUtils {
public static <T> List<T> transitionDtos(Object sourceList, Class<?> beanClass) {
if (sourceList == null) {
return new ArrayList<>();
}
List<Object> sList = (List<Object>) sourceList;
if (sList.isEmpty()) {
return new ArrayList<>();
}
List<Object> btoList = new ArrayList<>(sList.size() * 2);
try {
for (Object so : sList) {
Object bto = beanClass.newInstance();
BeanUtils.copyProperties(so, bto);
btoList.add(bto);
}
return (List<T>) btoList;
} catch (Exception e) {
return new ArrayList<>();
}
}
public static <T> T transitionDto(Object source, Class<?> beanClass) {
if (source == null) {
return null;
}
try {
Object bto = beanClass.newInstance();
BeanUtils.copyProperties(source, bto);
return (T)bto;
} catch (Exception e) {
return null;
}
}
}
...@@ -18,7 +18,7 @@ public enum RCode implements StatusCode { ...@@ -18,7 +18,7 @@ public enum RCode implements StatusCode {
PARAM_ERROR(1002, "参数错误"), PARAM_ERROR(1002, "参数错误"),
RESPONSE_PACK_ERROR(1003, "包装R失败"), RESPONSE_PACK_ERROR(1003, "包装R失败"),
SELECT_PARAMS_ERROR(1004, "查询条件错误"), SELECT_PARAMS_ERROR(1004, "查询条件错误"),
REDIS_PUSH_DATA_NOT_EXIT(1005, "数据已过期或不存在,请重上传;"), REDIS_PUSH_DATA_NOT_EXIT(1005, "数据已过期或不存在,请重上传;"),
/** /**
* 业务统一编码(不分模块) * 业务统一编码(不分模块)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论