MapKey mapKey = new MapKey(reqId, name, status);
LinkedHashMap<Object, List<Dashboard>> map = new LinkedHashMap<>();
mapkey类:
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;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
//All getters and setters
pojo类:
public class Dashboard {
int requestId;
String loginUser;
int price;
int status;
public int getrequestId() {
return requestId;
}
public void setrequestId(int requestId) {
requestId= requestId;
}
//All getters and setters
jsp代码:
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="1" style="text-align: center;">
<TR>
<c:forEach var="entry" items="${map}">
<TH>${entry.key}</TH>
</c:forEach>
</TR>
//iterate again
<c:forEach var="entry" items="${map}">
//entry.value is ArrayList so we can iterate with c:forEach
<c:forEach var="headers" items="${entry.value}">
<TR>
<TD>${headers}</TD>
</TR>
</c:forEach>
</c:forEach>
</TABLE>
输入:
MapKey [reqid=123, name=A,status=1]:[Dashboard [reqid=123, NAME=A, PRICE=5,STATUS=2],Dashboard [reqid=123, NAME=A, PRICE=10,STATUS=3],...,..]
MapKey [reqid=456, name=B,status=2]:[Dashboard [reqid=456, NAME=B, PRICE=20,STATUS=3],Dashboard [reqid=456, NAME=B, PRICE=25,STATUS=2],...,..]
预期产量:
123 A 1 ///Table header
123 A 5 2
123 A 10 3
//N no of rows
456 B 2 ///Table header
456 B 20 3
456 B 25 2
//N no of rows
我有一个Map,其中key是一个对象,value是list.arraylist由每个惟一的reqid作为对象的行组成。在Map中,键是我的表头,Map中的值是该表头的表数据。键取决于sql中的数据。它可以根据数据而变化。我想将每个键显示为表头,将其所有相关数据显示为表的行。我在jsp中编写了为每个键创建表的代码。我是java开发的新手,所以这就是我能写的。我需要帮助来实现预期的输出。
1条答案
按热度按时间oknwwptz1#
下面给出了一个最小的、可验证的示例:
Jmeter 板.java:
mapkey.java文件:
appcontroller.java:
我的页面.jsp:
输出: