| | |
| | | |
| | | |
| | | import org.apache.commons.beanutils.BeanUtils; |
| | | import org.apache.commons.beanutils.ConvertUtils; |
| | | import org.apache.commons.beanutils.Converter; |
| | | import org.apache.commons.beanutils.PropertyUtils; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | public final class BeanConvertUtil { |
| | | |
| | | private BeanConvertUtil() { |
| | | } |
| | | |
| | | static { |
| | | ConvertUtils.register(new Converter() { //注册一个日期转换器 |
| | | |
| | | public Object convert(Class type, Object value) { |
| | | Date date1 = null; |
| | | if (value instanceof String) { |
| | | String date = (String) value; |
| | | SimpleDateFormat sdf = null; |
| | | if (date.contains(":")) { |
| | | sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | } else { |
| | | sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | } |
| | | try { |
| | | date1 = sdf.parse(date); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return date1; |
| | | } |
| | | return value; |
| | | } |
| | | }, Date.class); |
| | | |
| | | ConvertUtils.register(new Java110StringConvert(), String.class); |
| | | } |
| | | |
| | | |
| | |
| | | returnModel = t.newInstance(); |
| | | BeanUtils.copyProperties(returnModel, orgBean); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("bean转换bean失败", e); |
| | | } |
| | | return returnModel; |
| | |
| | | * @param orgBean 原始bean |
| | | * @return map对象 |
| | | */ |
| | | public static Map beanCovertMap(Object orgBean) { |
| | | public static Map beanCovertMap(Object orgBean) { |
| | | Map newMap = null; |
| | | |
| | | try { |