2014年1月7日星期二

Scores java reflection mechanism neighborhoods seek to understand God 's great advice ~

[size = 18px] hibernate read out the list I use , I would like to turn into a List
Get reflection by Field Object names marked with , ah to map
I know the idea but do not know how depressing to realize
[/ size]
------ Solution - -------------------------------------------

Great God set out
------ Solution --------------------------------- -----------
God out of the top big
------ Solution - -------------------------------------------
http:// blog.csdn.net/snihcel/article/details/7270502

look at this
------ Solution --------------------------------- -----------
reference I have here the most simple Lie himself wrote the line : http://blog.csdn.net/withiter/article/details/8859399
------ Solution ---------------------------------------- ----
forget to wait for the god review
------ Solution -------------------------- ------------------
hibernate return this List elements of this object [] are not necessarily inside the entity class object , If it is not an entity class object landlord sql queries, but to get a collection of some of the fields , then this object [] which is filled with an array of those queries is likely to be out of the field so that they would become [int, String , boolean, ...] so the data array.
If the landlord does query is an entity class object , then do not use any reflection , the direct use of commons-beanUtils Tools

public List<Map> reflectObjToMap(List<Object[]> list){
    List<Map> list=new ArrayList<Map>(); 
    for(Object[] object:list){
        for(Object obj:object){
            Map map=BeanUtils.describe(obj);
            list.add(map);
        }
    }
    return list;    
}

------ Solution ------------------------------------- -------

  
I see trouble code :   
  

public void reflectObjToMap(List<Object[]> list){

for(Object[] object:list){
for(Object obj:object){
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {

System.out.println(field.getName());

}
}

}
 

upstairs to say, you can print out obj look
------ Solution ----------------------- ---------------------
great God ? Seek advice code. . .  
only need to open Eclipes then copied into running it. Very simple.
In addition to my personal experience, the actual project reflex mechanism is rarely used . But a lot of that is reflective of our familiar frameworks such as Struts , with its implementation principle .
------ Solution ---------------------------------------- ----
I came to learn , somewhat difficult ah
------ For reference only ----------------------- ----------------


I see trouble code :

public void reflectObjToMap(List<Object[]> list){

for(Object[] object:list){
for(Object obj:object){
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {

System.out.println(field.getName());

}
}

}

------ For reference only ----------------------------------- ----


I am a SQL query using the hibenate 's , List returned results returned not right ~
------ For reference only -------- -------------------------------
great God ? Seek advice code. . .

没有评论:

发表评论