How to get datas from List<Object> (Java)?

前端 未结 5 1972
我在风中等你
我在风中等你 2020-12-31 19:12

I`m new in Java and have a problem with showing data from a list of objects. I have a simple method, which should collect data across multiple tables and return it to my con

5条回答
  •  爱一瞬间的悲伤
    2020-12-31 19:22

    Do like this

    List list = HQL.list(); // get your lsit here but in Object array
    

    your query is : "SELECT houses.id, addresses.country, addresses.region,..."

    for(Object[] obj : list){
    String houseId = String.valueOf(obj[0]); // houseId is at first place in your query
    String country = String.valueof(obj[1]); // country is at second and so on....
    .......
    }
    

    this way you can get the mixed objects with ease, but you should know in advance at which place what value you are getting or you can just check by printing the values to know. sorry for the bad english I hope this help

提交回复
热议问题