巴巴运动网的产品类别展示
1、项目图解
这里面好多页面都是错的,只是个模板,暂时用不上,需要的代码我会全部贴出来,最后做完的时候我会把项目发上来
2、首先我们引入相应的jar包
3、首先我们组装整个页面的整体格局
页面的素材我会上传的,链接是:http://download.csdn.net/detail/cutter_point/8803985
ProductTypeAction.java
/**
* 功能:这个是实现产品类和web层的交互
* 时间:2015年5月16日10:50:36
* 文件:ProductTypeAction.java
* 作者:cutter_point
*/
packagecom.cutter_point.web.action.product;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
importorg.springframework.stereotype.Component;
import com.cutter_point.bean.PageIndex;
import com.cutter_point.bean.PageView;
import com.cutter_point.bean.QueryResult;
import com.cutter_point.bean.WebTool;
importcom.cutter_point.bean.product.ProductType;
importcom.cutter_point.service.product.ProductTypeService;
importcom.opensymphony.xwork2.ActionContext;
importcom.opensymphony.xwork2.ActionSupport;
//@Namespace("/product")
@Component
@Scope("prototype")
public class ProductTypeAction extendsActionSupport
{
@Resource
privateProductTypeService productTypeService;
privateint page;
@Override
publicString execute() throws Exception
{
Maprequest = (Map)ActionContext.getContext().get("request");
PageView<ProductType>pageview = new PageView<ProductType>(12, this.getPage());
intfirstindex = (pageview.getCurrentpage() - 1) * pageview.getMaxresult(); //得到从哪个开始索引的值
LinkedHashMap<String,String> orderby = new LinkedHashMap<String, String>();
orderby.put("typeid","desc");
QueryResult<ProductType>qr = productTypeService.getScrollData(ProductType.class, firstindex,pageview.getMaxresult(), "o.visible = ?",
newObject[]{true}, orderby);
pageview.setQueryResult(qr);
request.put("pageView",pageview);
// ProductTypept = productTypeService.find(ProductType.class, 3);
// intmaxresult = 12; //每页显示最多的条数
// longpageuse1 = qr.getTotalrecord() % pageview.getMaxresult();
// longpageuse2 = qr.getTotalrecord() / pageview.getMaxresult();
// longtotalpage = pageuse1 == 0 ? pageuse2 : pageuse2 + 1;
// PageIndexpageindex = WebTool.getPageIndex(pageview.getMaxresult(), this.getPage(),totalpage);
// request.put("productType",qr.getResultList());
// request.put("totalpage",totalpage);
// System.out.println("pageindex= " + pageindex.getStartpage() + " <=> " +pageindex.getEndpage());
// System.out.println(pt);
return"list";
}
publicint getPage()
{
returnpage < 1 ? 1 : page;
}
publicvoid setPage(int page)
{
this.page= page;
}
publicProductTypeService getProductTypeService()
{
returnproductTypeService;
}
publicvoid setProductTypeService(ProductTypeService productTypeService)
{
this.productTypeService= productTypeService;
}
}
producttypelist.jsp
显示产品分类的页面
<%@ page isELIgnored="false"contentType="text/html;charset=UTF-8" %>
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>产品类别管理</title>
<meta http-equiv="Content-Type"content="text/html; charset=UTF-8">
<link rel="stylesheet"href="../css/vip.css" type="text/css">
<script type="text/javascript">
//到指定的分页页面
function topage(page)
{
document.getElementById("page").value = page;
//alert(document.getElementById("page").value);
//document.form1.method= 'post';
//document.form1.submit();
var obj = document.getElementsByName("form1").item(0).submit();
}
</script>
<SCRIPT language=JavaScriptsrc="../js/FoshanRen.js"></SCRIPT>
</head>
<body bgcolor="#FFFFFF"text="#000000" marginwidth="0" marginheight="0">
<form id="form11"name="form1" action="producttype"method="post">
<s:hidden id="page"name="page" />
<table width="98%" border="0"cellspacing="1" cellpadding="2"align="center">
<tr ><td colspan="6" bgcolor="6f8ac4" align="right" >
<%@ include file="../share/fenye.jsp" %>
</td></tr>
<tr>
<td width="8%" bgcolor="6f8ac4"><div align="center"><fontcolor="#FFFFFF">代号</font></div></td>
<td width="5%" nowrapbgcolor="6f8ac4"><div align="center"><fontcolor="#FFFFFF">修改</font></div></td>
<td width="20%" bgcolor="6f8ac4"><div align="center"><fontcolor="#FFFFFF">产品类别名称</font></div></td>
<td width="10%"nowrap bgcolor="6f8ac4"><div align="center"><fontcolor="#FFFFFF">创建下级类别</font></div></td>
<td width="15%"bgcolor="6f8ac4"><div align="center"><fontcolor="#FFFFFF">所属父类</font></div></td>
<td nowrapbgcolor="6f8ac4"><div align="center"><fontcolor="#FFFFFF">备注</font></div></td>
</tr>
<!---------------------------LOOPSTART------------------------------>
<s:iterator value="#request.pageView.records"var="productType">
<tr>
<td bgcolor="f5f5f5"><div align="center"><s:propertyvalue="#productType.typeid"/></div></td>
<td bgcolor="f5f5f5"><div align="center">
<img src="../images/edit.gif"width="15" height="16"border="0"></a></div></td>
<td bgcolor="f5f5f5"><div align="center"><a href=""><s:property value="#productType.name"/></a></div></td>
<td bgcolor="f5f5f5"><div align="center"><a href="<s:url action="/control/product/type/manage"/>?method=addUI&parentid=#">创建子类别</a></div></td>
<td bgcolor="f5f5f5"align="center"><s:if test="%{#productType.parent!= null}"><s:property value="#productType.parent"/></s:if></td>
<td bgcolor="f5f5f5"><s:propertyvalue="#productType.note"/></td>
</tr>
</s:iterator>
<!----------------------LOOPEND------------------------------->
<tr>
<td bgcolor="f5f5f5" colspan="6"align="center"><table width="100%"border="0" cellspacing="1"cellpadding="3">
<tr>
<td width="5%"></td>
<td width="85%">
<input name="AddDic"type="button" class="frm_btn"id="AddDic" onClick="javascript:"value="添加类别">
<input name="query"type="button" class="frm_btn"id="query" onClick="javascript:"value=" 查询 ">
</td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
4、struts2的配置
<?xml version="1.0"encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD StrutsConfiguration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<include file="struts-default.xml" />
<constant name="struts.ObjectFactory" value="spring" /><!-- 表示这里面的action由spring进行创建 -->
<constant name="struts.devMode" value="true" />
<package name="control" namespace="/control"extends="struts-default">
<action name="center-*"><!-- 直接跳转,不需要经过class的验证,默认返回success -->
<result name="success">/page/controlcenter/{1}.jsp</result>
</action>
<action name="producttype" class="productTypeAction" method="execute">
<result name="list">/page/product/producttypelist.jsp</result>
</action>
</package>
</struts>
5、接下来我们测试一下页面的效果
我们访问这个网站
http://localhost:8080/babaSport_0800_s2sh_producttypelist_web/control/center-main
我们把产品管理打开
由于所属父类展示没做,所以还无法显示
关于网站为什么要这样写,上一篇blog有介绍
6、总结
下一节我们将会开始处理父类的子类的子类的子类。。。
显示问题了,这里我们先把数据库里面所有的类别全部查询出来,不考虑所谓的先只显示父类的问题