Java 列表换位

Java 列表换位,java,jsp,web,code-snippets,Java,Jsp,Web,Code Snippets,我想做的是把我的清单换过来。确切地说,从一个列表到一个表格 在中,当我接收保存在数组{13}中的值时(此数组用0初始化。每月一个,不使用前0) 然后,这是我的代码片段,我在那里结巴了 我对需要添加到组描述并在同一行中打印所有金额的条件有点困惑 while ( rsSol.next() ) { //where i (re)write description if ( desc.equals(empty_string) ){ desc = rsSol

我想做的是把我的清单换过来。确切地说,从一个列表到一个表格

在中,当我接收保存在数组{13}中的值时(此数组用0初始化。每月一个,不使用前0)

然后,这是我的代码片段,我在那里结巴了

我对需要添加到组描述并在同一行中打印所有金额的条件有点困惑

while ( rsSol.next() ) {
    //where i (re)write description
    if ( desc.equals(empty_string) ){
        desc        =  rsSol.getString("description");
    }

    if ( !desc.equals(rsSol.getString("giro")) && count > 1 ){
        desc        = rsSol.getString("giro");
    } 

    // Where i print the description
    <tr class>
        <td border='0' ALIGN='left'>    desc.toLowerCase()  </td>

        // Where i print the array
        for(int i=1; i<=12; i++){
            <td border='0' ALIGN='right'>   values[i])  </td>
        }

        // Where i print the sum of all months
        <td border='0' ALIGN='right'>   monthTotal  </td>
    </tr>

    // Setting values to 0 and cleaning the array
    mon_amounth =   0;

    for ( int i=1 ; i<=12 ; i++ ) {
        values[i] = 0;
    }
}
while(rsSol.next()){
//我(重新)写描述的地方
if(desc.equals(空字符串)){
desc=rsSol.getString(“说明”);
}
如果(!desc.equals(rsSol.getString(“giro”)&&count>1){
desc=rsSol.getString(“giro”);
} 
//我在哪里打印描述
描述toLowerCase()
//我在那里打印数组

对于(inti=1;i,您需要迭代结果集,然后打印您的总数。 我想你有不同的描述,应该计算总数。 您可以使用HashMap,该HashMap不允许将重复的键作为描述,将值作为总数

// collect sums
    Map<String, Integer[]> totals = new HashMap<>();
    while ( rsSol.next() ) {
        if ( desc.equals("") ){
            desc =  rsSol.getString("description");
        }
        if ( !desc.equals(rsSol.getString("giro")) && count > 1 ){
            desc = rsSol.getString("giro");
        }
        totals.putIfAbsent(desc, new Integer[12]);
        Integer[] totalSums = totals.get(desc);
        for(int i = 0; i < 12; i++){
            totalSums += values[i];
        }
    }

// print your results
    for (String desc : totals.keySet()) {
       <tr class>
            <td border='0' ALIGN='left'>    desc.toLowerCase()  </td>

                // Where i print the array
                for(int i=1; i<=12; i++){
                <td border='0' ALIGN='right'>   totals.get(desc)  </td>
                }

                // Where i print the sum of all months
            <td border='0' ALIGN='right'>   monthTotal  </td>
        </tr> 
    }
//收集总和
Map totals=新的HashMap();
while(rsSol.next()){
如果(描述等于(“”){
desc=rsSol.getString(“说明”);
}
如果(!desc.equals(rsSol.getString(“giro”)&&count>1){
desc=rsSol.getString(“giro”);
}
总计。putIfAbsent(描述,新整数[12]);
整数[]totalSums=totals.get(desc);
对于(int i=0;i<12;i++){
总和+=数值[i];
}
}
//打印结果
对于(字符串描述:totals.keySet()){
描述toLowerCase()
//我在那里打印数组

对于(inti=1;iThanks),这是非常有用的
// collect sums
    Map<String, Integer[]> totals = new HashMap<>();
    while ( rsSol.next() ) {
        if ( desc.equals("") ){
            desc =  rsSol.getString("description");
        }
        if ( !desc.equals(rsSol.getString("giro")) && count > 1 ){
            desc = rsSol.getString("giro");
        }
        totals.putIfAbsent(desc, new Integer[12]);
        Integer[] totalSums = totals.get(desc);
        for(int i = 0; i < 12; i++){
            totalSums += values[i];
        }
    }

// print your results
    for (String desc : totals.keySet()) {
       <tr class>
            <td border='0' ALIGN='left'>    desc.toLowerCase()  </td>

                // Where i print the array
                for(int i=1; i<=12; i++){
                <td border='0' ALIGN='right'>   totals.get(desc)  </td>
                }

                // Where i print the sum of all months
            <td border='0' ALIGN='right'>   monthTotal  </td>
        </tr> 
    }