废话不多说 直接看service
action就不看了 就是set
直接到JSP吧
package com.hcwy.jsp.product.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import com.hcwy.basic.jdbc.excute.MySqlDBExecute;
import com.hcwy.model.product.bean.Product;
public class IndexService {
MySqlDBExecute execute=new MySqlDBExecute();
//按总分层取数据
public List findByCent(){
String sql = "select p.proplace,p.proid,p.proname,p.proprive,p.centid,c.centname,p.fid from product p,cent c where c.centid=p.centid order by c.centname desc";
List result = execute.findMap(sql);
return result;
}
public Map get2() {
IndexService is=new IndexService();
List list=is.findByCent();
Map map1=new HashMap();
String cent="";
List list1=new ArrayList();
HashMap hap = new HashMap();
String preCentName = "";
Vector vec = null;
for (int i = 0; i < list.size(); i ++) {
HashMap map=(HashMap)list.get(i);
String centName = map.get("centname").toString();
String proPlace = map.get("proplace").toString();
String centid=map.get("centid").toString();
String proid=map.get("proid").toString();
if (centName.equals(preCentName)) {
vec.add(centName);
vec.add(proPlace);
vec.add(centid);
vec.add(proid);
} else {
if (i != 0) {
hap.put(preCentName, vec);
}
vec = new Vector();
vec.add(centName);
vec.add(proPlace);
vec.add(centid);
vec.add(proid);
}
preCentName = centName;
}
hap.put(preCentName, vec);
return hap;
}
public Map get1() {
IndexService is=new IndexService();
List list=is.findByCent();
Map map1=new HashMap();
String cent="";
List list1=new ArrayList();
HashMap hap = new HashMap();
String preCentName = "";
Vector vec = null;
for (int i = 0; i < list.size(); i ++) {
HashMap map=(HashMap)list.get(i);
Product p=new Product();
p.setCentname(map.get("centname").toString());
p.setProplace(map.get("proplace").toString());
p.setCentid(Integer.parseInt(map.get("centid").toString()));
p.setProid(Integer.parseInt(map.get("proid").toString()));
if (p.getCentname().equals(preCentName)) {
vec.add(p);
} else {
if (i != 0) {
hap.put(preCentName, vec);
}
vec = new Vector();
vec.add(p);
}
preCentName = p.getCentname();
}
hap.put(preCentName, vec);
return hap;
}
}
action就不看了 就是set
直接到JSP吧
<%@ page language="java" pageEncoding="gbk"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<html:html lang="true">
<head>
<html:base />
<title>test.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<logic:iterate id="hep" name="list">
<bean:write name="hep" property="key"/>
<bean:define id="asd" name="hep" property="value"></bean:define>
<br>
<logic:iterate id="hep1" name="asd">
${hep1.centname }
</logic:iterate>
<br>
</logic:iterate>
</body>
</html:html>