Java 如何为hashmap值动态创建表

Java 如何为hashmap值动态创建表,java,list,data-structures,collections,hashmap,Java,List,Data Structures,Collections,Hashmap,我已成功地将数据库值存储在hashmap中。如何在动态变化的表中显示jsp页面中的hashmap值。看下面我的动作课,这里市场代表国家。每个国家/地区有4个值,分别是count、dataamount、result和orderdate package com.pkg; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; impor

我已成功地将数据库值存储在hashmap中。如何在动态变化的表中显示jsp页面中的hashmap值。看下面我的动作课,这里市场代表国家。每个国家/地区有4个值,分别是count、dataamount、result和orderdate

package com.pkg;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class JanuaryAction {
    private String from; // creating variables to access input values.
    private String to; // creating variables to access input values.
    Map abc1 = new HashMap(); // Getting the map objects to store tha values

    public Map getAbc1() { /* Creating the setters and getters */
        return abc1;
    }

    public void setAbc1(Map abc1) {
        this.abc1 = abc1;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public Map<String, String> getAbc() {
        return abc;
    }

    public void setAbc(Map<String, String> abc) {
        this.abc = abc;
    }

    Map<String, String> abc = new HashMap<String, String>();

    Map<String, List<ReportClass>> map = new HashMap<String, List<ReportClass>>(); // Using
                                                                                    // Map
                                                                                    // interface
                                                                                    // implementing
                                                                                    // hashmap

    public Map<String, List<ReportClass>> getMap() {
        return map;
    }

    public void setMap(Map<String, List<ReportClass>> map) {
        this.map = map;
    }

    public String execute() throws Exception {

        String fromdate = getFrom();
        System.out.println(fromdate);
        String todate = getTo();
        System.out.println(todate);

        Connection con = GetCon.getCon();
        Statement statement = con.createStatement();

        ResultSet resultset = statement
                .executeQuery("SELECT MarketPlace,OrderDate, ROUND(SUM(Total),2), COUNT(*) , ROUND(ROUND(SUM(Total),2)/ COUNT(*),2) FROM vend_printed WHERE OrderDate >='"
                        + fromdate + "' AND OrderDate <='" + todate + "' GROUP BY OrderDate,MarketPlace");

        while (resultset.next()) {
            String marketplace = resultset.getString(1);// get the first column
                                                        // in marketplace
            String orderdate = resultset.getString(2);// get the second column
                                                        // in orderdate
            Double datamount = resultset.getDouble(3);// get the third column in
                                                        // datamount
            Integer count = resultset.getInt(4);// get the fourth column in
                                                // count
            Double result = resultset.getDouble(5); // get the fifth column in
                                                    // result
            ReportClass a = new ReportClass(); // create an object to access
                                                // pojo class.

            a.setMarketplace(marketplace); // setting the values in pojo class
            a.setOrderdate(orderdate);
            a.setDataamount(datamount);
            a.setCount(count);
            a.setResult(result);

            if (map.get(marketplace) != null) { // if the value in marketplace
                                                // is null then go to else
                                                // statement or go to if
                                                // statement.
                map.get(marketplace).add(a); // using the key add one complete
                                                // row values from a to
                                                // marketplace
            } else {
                List<ReportClass> optionsVO = new ArrayList<ReportClass>(); // create
                                                                            // a
                                                                            // list
                                                                            // optionsVo
                optionsVO.add(a); // store Reportclass values in List.
                map.put(marketplace, optionsVO); // storing it in map.
                /* System.out.println(map.get(marketplace).toString()); */
            }

        }
        Set s = map.entrySet(); // A map entry (key-value pair).creating Set
                                // interface.
        Iterator i = s.iterator();
        while (i.hasNext()) {

            List<ReportClass> tempList = (List<ReportClass>) ((Entry) i.next()).getValue(); // creating
                                                                                            // a
                                                                                            // temporary
                                                                                            // list

            for (ReportClass reportClassObj : tempList) {
                System.out.println(reportClassObj.getMarketplace());// display
                                                                    // values.
                System.out.println(reportClassObj.getDataamount());
                System.out.println(reportClassObj.getOrderdate());
                System.out.println(reportClassObj.getCount());
                System.out.println(reportClassObj.getResult());
            }
        }

        /* System.out.println(map.size()); */
        return "success";
    }
}

使用下面的代码在jsp中检索它

<s:iterator var="studentEntry" status="stat" value="map.entrySet()">  <br><br><br>
Marketplace Name is: <s:property value="%{#studentEntry.getKey()}"/> <br>
Value: <s:property value="%{#studentEntry.getValue()}"/><br><br><br>

</s:iterator>

使用下面的代码在jsp中检索它

<s:iterator var="studentEntry" status="stat" value="map.entrySet()">  <br><br><br>
Marketplace Name is: <s:property value="%{#studentEntry.getKey()}"/> <br>
Value: <s:property value="%{#studentEntry.getValue()}"/><br><br><br>

</s:iterator>

动态更改表是什么意思?你试过什么?发布一些代码。请检查我的更新。我成功了,直到我在hashmap中获得了值,然后我努力将它带到jsp页面,因为它需要随着数据的进入而动态更改表。格式化你的代码。发布你的jsp代码。尝试提供尽可能多的信息,让人们更容易回答。因为我不知道如何开始。。所以我并没有在JSP中写任何东西,动态更改表是什么意思?你试过什么?发布一些代码。请检查我的更新。我成功了,直到我在hashmap中获得了值,然后我努力将它带到jsp页面,因为它需要随着数据的进入而动态更改表。格式化你的代码。发布你的jsp代码。尝试提供尽可能多的信息,让人们更容易回答。因为我不知道如何开始。。所以我没有用jsp写任何东西