Convert the map object in the List set to the instance code in the form of List <Object>, maplist
In this example, the map object in the List set is converted to the List <Object> form. The complete code is as follows:
Import java. util. arrayList; import java. util. hashMap; import java. util. iterator; import java. util. list; import java. util. map; import org. apache. commons. beanutils. convertUtils; import org. apache. commons. beanutils. propertyUtils; public class EntityBean {/*** this method implements the automatic * encapsulation function * of data returned by the Map set returned by JDBCTemplate *. The List set stores a series of MAP * objects, obj is a javaBean * @ param listMap Set * @ param objjavaBean object * @ return */public List par Se (List list, Class obj) {// generate ArrayList ary = new ArrayList (); // traverse all data in the set for (int I = 0; I <list. size (); I ++) {try {// generate the Object calendar and encapsulate all parameters in the MAP into the Object. Object o = this. addProperty (Map) list. get (I), obj. newInstance (); // Add the object to the Collection ary. add (o);} catch (InstantiationException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke. printStack Trace () ;}/// return the encapsulated set return list;}/** the value in the Map object is name = aaa, value = bbb call method addProperty (map, user ); * automatically assigns values in the map to the user class * this method is used in combination with the jdbcTemplete of the Spring framework to store the names and values set in * @ param map * @ param obj to be encapsulated object * @ return encapsulated Object */public Object addProperty (Map map Map, object obj) {// traverse all names Iterator it = map. keySet (). iterator (); while (it. hasNext () {// obtain the name String name = it. next (). toString (); // obtain the value String value = map. get (name ). toStrin G (); try {// The Class type that gets the value = PropertyUtils. getPropertyType (obj, name); if (type! = Null) {// set the parameter PropertyUtils. setProperty (obj, name, ConvertUtils. convert (value, type) ;}} catch (Exception ex) {ex. printStackTrace () ;}} return obj ;}// usage method List stuGroupList2 = new ArrayList (); EntityBean entbean = new EntityBean (); for (DynaBean stubean: stuGroupList) {if (stubean. get ("GROUP_ID ")! = Null & stubean. get ("GROUP_ID "). equals (group_id) {LinkedHashMap map = new LinkedHashMap (); map. put ("choose_id", stubean. get ("CHOOSE_ID"); map. put ("group_user_typecode", stubean. get ("GROUP_USER_TYPECODE"); map. put ("group_id", stubean. get ("GROUP_ID"); map. put ("realname", stubean. get ("REALNAME"); stuGroupList2.add (map) ;}} stuGroupList2 = entbean. parse (stuGroupList2, stuGroup. class );
Summary
The above is all about converting the map object in the List set into the List <Object> form instance code. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!