【发布时间】:2016-10-14 01:51:16
【问题描述】:
我有一个对象列表(来自一个选择查询),我想将它转换为一个数组,并且我想将查询的每一列放在数组中的一列中。我在论坛尝试了很多解决方案,但我没有找到解决方案。
在我的 bean 中,我有以下列表:
private List<PhBonCmd> listEntree; // The PhBonCmd is an object model imported has attributes like codeprod , quant ,...
.....
String sql ="select c.codeprod as codeprod , c.quant as quant ,c.date_cmd as date_cmd, c.date_expir as date_expir,c.numbco as numbco, c.auteur as auteur,"
+"c.idcmd as idcmd ,f.nomfourn as nomfourn ,coalesce(c.quant_livre, 0) as quant_livre ,m.libelle as libelle "
+"from commandes c,listeproduit m,fournisseur f "
+"where c.codeprod=m.codeproduit and c.fourn=f.idfourn and c.statut='IN' and c.numbco ='"+getNumbco()+"' ";
listEntree = (List<PhBonCmd>) this.bcService.execRequete(sql);//Here the results of the sql query
现在我想要将 List (listEntree) 的每一列放入一个多维数组列表中,这样就好像我想访问数组列表中的特定单个值一样。
【问题讨论】:
-
先获取执行请求的结果类型,然后如果是多维则
List<PhBonCmd>强制转换正确,否则初始化listEntree = new List<PhBonCmd>并添加每个项目 -
您好,我找到了 Dans stackoverflow.com/questions/14773264/…提供的解决方案
标签: java arrays list multidimensional-array