不用递归做递归的效果 菜单排序

废话不多说 直接看service

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值