在地图中获取最后一行的数据

public class MapKey {
  private Integer id;
  private String name;
  private Integer status;

   public MapKey(Integer id, String name,Integer status) {
    this.id = id;
    this.name = name;
    this.status=status;
  }
   @Override toString,hashCode,equals
  public class Dashboard {
  int REQUEST_ID; 
  String name;
  int price;
  int status;
  public int getREQUEST_ID() {
    return REQUEST_ID;
 }
 public void setREQUEST_ID(int rEQUEST_ID) {
    REQUEST_ID = rEQUEST_ID;
 }
 //getters and setters



 public class DBConnection {
public ArrayList<Dashboard>  getStoreResult() {
    ArrayList<Dashboard> dashRec=new ArrayList<Dashboard>();
    Dashboard dash = new Dashboard();

    try{
        Class.forName("");
        Connection con=DriverManager.getConnection("");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery("");
        HashMap<Object, List<Dashboard>> map = new HashMap<>();
        int status=100;
        int reqid=0;
        String name1=null;
        while (rs.next()) {
            Integer id = rs.getInt(1);
            String name=rs.getString(2);
            if(reqid==0) {
                reqid=id;   
                name1=name;
            }
            if(reqid !=id) {
                MapKey key = new MapKey(reqid,name1,status);
                map.put(key, dashRec);
                reqid=id;
                name1=name;
                dashRec= new ArrayList<Dashboard>();
                status=100;
            }

            dash = new Dashboard();
            dash.setREQUEST_ID(id);
            dash.setLOGIN_USER(name);
            dash.setPRICE(rs.getInt(3));
            dash.setSTATUS(rs.getInt(4));
            dashRec.add(dash);
            if(rs.getInt(4)<=status) {
                status=rs.getInt(4);
            }
        }

我对Java比较陌生。 我的目标是创建一个映射。它具有集合的名称,名称和最低状态编号作为键。这里的集合是指属于特定Reqid的行。映射的值是一个由所有行作为对象组成的数组列表特定ID的输出类似: MapKey [reqid = 123,name = A,status = 1]:[资讯主页[reqid = 123,NAME = A,PRICE = 5,STATUS = 2],资讯主页[reqid = 123,NAME = A,PRICE = 10,STATUS = 3],...,..] 它仅捕获直到需求456的数据。但是我的代码无法捕获映射中最后一个唯一的需求行数据。

SQL DB

评论