5 changed files with 160 additions and 0 deletions
-
21src/main/java/com/gaotao/modules/purchasingManagement/controller/MaterialSplitController.java
-
17src/main/java/com/gaotao/modules/purchasingManagement/entity/ReferenceRollData.java
-
23src/main/java/com/gaotao/modules/purchasingManagement/service/Impl/MaterialSplitServiceImpl.java
-
11src/main/java/com/gaotao/modules/purchasingManagement/service/MaterialSplitService.java
-
88src/main/java/com/gaotao/modules/purchasingManagement/util/EntityBean.java
@ -0,0 +1,17 @@ |
|||||
|
package com.gaotao.modules.purchasingManagement.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class ReferenceRollData { |
||||
|
private String site; |
||||
|
private String partNo; |
||||
|
private String partDescription; |
||||
|
private String customerID; |
||||
|
private String fGPartNo; |
||||
|
private String supplierID; |
||||
|
private String supplierDesc; |
||||
|
private String SupplierDesc; |
||||
|
private String SupplierID; |
||||
|
private String PartDescription; |
||||
|
} |
||||
@ -0,0 +1,88 @@ |
|||||
|
package com.gaotao.modules.purchasingManagement.util; |
||||
|
|
||||
|
import org.apache.commons.beanutils.ConvertUtils; |
||||
|
import org.apache.commons.beanutils.PropertyUtils; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Iterator; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author ZuoWen |
||||
|
* @date 2022年04月18日 17:05 |
||||
|
*/ |
||||
|
public class EntityBean { |
||||
|
|
||||
|
/** |
||||
|
* 此方法实现JDBCTemplate |
||||
|
* 返回的Map集合对数据的自动 |
||||
|
* 封装功能 |
||||
|
* List集合存储着一系列的MAP |
||||
|
* 对象,obj为一个javaBean |
||||
|
* @param list Map集合 |
||||
|
* @param obj javaBean对象 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static List parse(List list,Class obj){ |
||||
|
//生成集合 |
||||
|
ArrayList ary = new ArrayList(); |
||||
|
//遍历集合中的所有数据 |
||||
|
for (int i = 0; i<list.size(); i++){ |
||||
|
try { |
||||
|
////生成对象实历 将MAP中的所有参数封装到对象中 |
||||
|
Object o = addProperty( (Map)list.get(i),obj.newInstance() ); |
||||
|
//把对象加入到集合中 |
||||
|
ary.add(o); |
||||
|
} |
||||
|
catch (InstantiationException e) { |
||||
|
// TODO Auto-generated catch block |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
catch (IllegalAccessException e) { |
||||
|
// TODO Auto-generated catch block |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
//返回封装好的集合 |
||||
|
return list; |
||||
|
} |
||||
|
/**Map对象中的值为 name=aaa,value=bbb |
||||
|
调用方法 |
||||
|
addProperty(map,user); |
||||
|
*将自动将map中的值赋给user类 |
||||
|
*此方法结合Spring框架的jdbcTemplete将非 |
||||
|
*常有用 |
||||
|
* @param map 存储着名称和值集合 |
||||
|
* @param obj 要封装的对象 |
||||
|
* @return封装好的对象 |
||||
|
*/ |
||||
|
public static Object addProperty(Map map, Object obj){ |
||||
|
//遍历所有名称 |
||||
|
Iterator it = map.keySet().iterator(); |
||||
|
while(it.hasNext()){ |
||||
|
//取得名称 |
||||
|
String name = it.next().toString(); |
||||
|
//取得值 |
||||
|
String value; |
||||
|
if(map.get(name) == null){ |
||||
|
value = null; |
||||
|
}else { |
||||
|
value = map.get(name).toString(); |
||||
|
} |
||||
|
try{ |
||||
|
//取得值的类形 |
||||
|
Class type = PropertyUtils.getPropertyType(obj, name); |
||||
|
if(type!=null){ |
||||
|
//设置参数 |
||||
|
PropertyUtils.setProperty(obj, name, ConvertUtils.convert(value, type)); |
||||
|
} |
||||
|
} |
||||
|
catch(Exception ex){ |
||||
|
ex.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
return obj; |
||||
|
} |
||||
|
} |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue