List<Object>转List<T>

Today encounter a trouble, the company has a project with a template package dao fuck check whether it is a method of data, or to check a method of data collection, all return Object or List <Object>

 

Since the object is simply not good operation Object, Object value which take to use Object [0] ... Object [1] In this way, fuck model entity classes do not have this shit stuff items, let me know who wrote it the framework, it can not be his non-playing feces

 

Baidu for a long time on the Internet how to switch to Object entity class object, a group of blind chicken children write what the hell, there is not a clear code implementation.

 

I finally found a can to use List <Object> turn List <T> any type of writing, as follows:

  List<Object>转List<User>:

    List <Object> objList = dao.select .... (); // query data, but returns List <Object> Object

    Object obj = (Object) objList; // Object type first converted into objList

    List <User> userList = (List <User>) Object; // then turn into any type of object you want

 

  List <Object> turn List <Map <String, Object >> is written in this way:

    

  List <Object> objList = dao.select .... (); // query data, but returns List <Object> Object

    Object obj = (Object) objList; // Object type first converted into objList

    List <Map <String, Object >> userList = (List <Map <String, Object >>) Object; // then turn into any type of object you want

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

...

Guess you like

Origin www.cnblogs.com/spll/p/12620387.html