| | |
| | | package com.boying.util; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.BeanUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import com.boying.entity.EnterPark; |
| | | |
| | | import java.beans.BeanInfo; |
| | | import java.beans.IntrospectionException; |
| | | import java.beans.Introspector; |
| | | import java.beans.PropertyDescriptor; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | List<Map<String,Object>> list = new ArrayList<>(); |
| | | for (EnterPark enterPark : enterParkList) { |
| | | int i = compareLicensePlates(carNo, enterPark.getCarNo()); |
| | | if (i<=2){ |
| | | Map<String, Object> map = BeanUtils.beanToMap(enterPark); |
| | | map.put("count",i); // 新增次数 |
| | | list.add(map); |
| | | if (i<2){ |
| | | Map<String, Object> returnMap = new HashMap<String, Object>(); |
| | | BeanInfo beanInfo = null; |
| | | try { |
| | | beanInfo = Introspector.getBeanInfo(enterPark.getClass()); |
| | | PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); |
| | | for (PropertyDescriptor pd : propertyDescriptors) { |
| | | String propertyName = pd.getName(); |
| | | if (!"class".equals(propertyName)) { |
| | | Method readMethod = pd.getReadMethod(); |
| | | Object result = readMethod.invoke(enterPark); |
| | | if (result != null) { |
| | | returnMap.put(propertyName, result); |
| | | } else { |
| | | returnMap.put(propertyName, ""); |
| | | } |
| | | } |
| | | } |
| | | } catch (IntrospectionException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvocationTargetException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | returnMap.put("count",i); // 新增次数 |
| | | list.add(returnMap); |
| | | } |
| | | } |
| | | return list; |