<repo_name>YOUYOU-xcu/Dogbaby<file_sep>/src/com/zhang/you/uibuilder/PhotographerUibuilder.java
﻿package com.zhang.you.uibuilder;
public class PhotographerUibuilder extends UibuilderBase {
	public  PhotographerUibuilder(String lanmuclassname){
		super("photographer", lanmuclassname, "name", "photo");
	}
}
<file_sep>/src/com/zhang/you/util/youUIHelper.java
package com.zhang.you.util;

import java.util.List;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;




public class youUIHelper {
	
	public static String getJsonFromList(List beanList){
		return getJsonFromList(beanList.size(),beanList);
	}

	private static String getJsonFromList(int recordTotal, List rows) {

		JSONObject jsonobject = new JSONObject();
		jsonobject.put("Rows", rows);
		jsonobject.put("Total",new Integer(recordTotal));
		
		return jsonobject.toString();
		
	}

}
<file_sep>/src/com/zhang/you/uibuilder/IndexColumnsBuilder.java
package com.zhang.you.uibuilder;

import java.util.List;

import com.zhang.you.dal.DALBase;
import com.zhang.you.entity.Indexcolumns;

public class IndexColumnsBuilder {

	
	public String buildColumns(){
		
		int columncontentsize=10;
		StringBuffer sb=new StringBuffer();
		ShangpinBuilder shangpinbuilder=new ShangpinBuilder();
		List<Indexcolumns>  list=DALBase.getEntity("indexcolumns", "");
		for (Indexcolumns indexcolumns : list) {
			sb.append(shangpinbuilder.buildImageShangpin(indexcolumns.getColid(), columncontentsize));
			sb.append("\r\n");
			
		}
		return sb.toString();
		
		
	}
	
	
}
<file_sep>/src/com/zhang/you/uibuilder/ShangpinBuilder.java
package com.zhang.you.uibuilder;

import java.text.MessageFormat;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;


import com.zhang.you.dal.DALBase;
import com.zhang.you.entity.*;
import com.zhang.you.uibuilder.UibuilderBase;


public class ShangpinBuilder extends UibuilderBase {

	
	
	
	public ShangpinBuilder(){
		
		super("shangpin", "box", "name", "tupian");
		
		
	}
	public ShangpinBuilder(String cssclassname){
		
		super("shangpin", cssclassname, "name", "tupian");
		
	}
	/**
	 * 图片
	 * @param spcid
	 * @param maxcount
	 * @return
	 */
	public String buildImageShangpin(int spcid,int maxcount)
	{
		StringBuilder sb=new StringBuilder();
		Spcategory spcategory =(Spcategory)DALBase.load("spcategory", "where id="+spcid);
		if(spcategory==null)
			return "";
		
		List<Shangpin> shangpinlist=null;
		if(maxcount!=-1)
			 shangpinlist=findBySpcateid(spcid,maxcount);
		else 
			 shangpinlist=findBySpcateid(spcid);
		//得到商品信息
		sb.append(buildImageLanmu(shangpinlist, spcategory.getMingcheng()));
		
		
		return sb.toString();
		
	}
	
	public String buildTextShangpin(int spcid,int maxcount)
	{
		StringBuilder sb=new StringBuilder();
		Spcategory spcategory =(Spcategory)DALBase.load("spcategory", "where id="+spcid);
		if(spcategory==null)
			return "";
		
		List<Shangpin> shangpinlist=null;
		if(maxcount!=-1)
			 shangpinlist=findBySpcateid(spcid,maxcount);
		else 
			 shangpinlist=findBySpcateid(spcid);
		//得到商品信息
		sb.append(buildTextLanmu(shangpinlist, spcategory.getMingcheng()));
		
		
		return sb.toString();
		
	}
	
	
	public String  buildHotSale(){
		
		StringBuilder sb=new StringBuilder();
		
		List<Shangpin> shangpinlist=getHotSales();
		
		//得到商品信息
		sb.append(buildImageLanmu(shangpinlist, "热买商品推荐"));
		
		
		return sb.toString();
		
	}
	 
	//推荐商品
     public String  buildRecomment(){
		
		StringBuilder sb=new StringBuilder();
		
		List<Shangpin> shangpinlist=getRecomment();
		
		//得到商品信息
		sb.append(buildImageLanmu(shangpinlist, "精品推荐"));
    	return sb.toString();
	}
     
     //最新商品 
     public String  buildLastest(){
		
		StringBuilder sb=new StringBuilder();
		
		List<Shangpin> shangpinlist=getNewest();
		
		//得到最新商品信息 
		sb.append(buildImageLanmu(shangpinlist, "新货上架"));
    	return sb.toString();
	} 
	
     public String  buildViewedProduct(HttpServletRequest request){
 		
 		StringBuilder sb=new StringBuilder();
 		//获取历史浏览
 		List<String> ids=ProductViewHistory.HistoryView(request);
 		String temids="";
 		int i=0;
 		for(String id : ids){
 			temids+=id;
 			if(i<ids.size()-1){
 				temids+=",";
 			}
 			i++;
 		
 		}
 		if(ids!=null&&ids.size()>0){
 		  List<Shangpin> shangpinlist=DALBase.getEntity("shangpin", " where id in ("+temids+")");
 		
 		//得到最新商品信息 
 		  sb.append(buildImageLanmu(shangpinlist, "猜你喜欢的商品"));
 		}
     	return sb.toString();
 	} 
	
    public String search(String spname,String classname){
		
	   StringBuffer sb=new StringBuffer();
	    int i=0;
	    
	    sb.append(MessageFormat.format("<dd class=\"{0}\">",classname));
	    sb.append("\r\n");
		  
		List<Shangpin> listxinxi=findBySpname(spname);
		for(Iterator<Shangpin> iterator = listxinxi.iterator();iterator.hasNext();){
		
		 Shangpin shangpin=iterator.next();
		  
		 
		  sb.append(" <div class=\"picturebox\">");
		  sb.append("\r\n");
		  
		  sb.append(MessageFormat.format("<a href=\"shangpininfo.jsp?id={0}\">",shangpin.getId()));
		  sb.append(MessageFormat.format("<img src=\"{0}\"/> ",shangpin.getTupian()));
		  sb.append("</a>");
		  sb.append("\r\n");
		  sb.append(MessageFormat.format("<span><a href=\"shangpininfo.jsp?id={0}\">{1}</a></span>",shangpin.getId(),shangpin.getName()));
		  
		  sb.append("</div>");
		  
		 
		  i++;
		}
		 sb.append("</dd>");
		 sb.append("\r\n");
		 return sb.toString();
		
		
	}
	
    private List<Shangpin> findBySpname(String spname) {
	
        List<Shangpin> list=DALBase.runNativeSQL(MessageFormat.format("select * from  shangpin where name like ''%{0}%'' ",spname),Shangpin.class);
		
		return list;
    
    }

	

	private  List<Shangpin> findBySpcateid(int spcid){
		
		List<Shangpin> list=DALBase.runNativeSQL(MessageFormat.format("select * from  shangpin where sptypeid={0} ",spcid),Shangpin.class);
		
		return list;
	}
	
   private  List<Shangpin> getHotSales(){
		
		List<Shangpin> list=DALBase.getEntity("shangpin"," where hot=1 ");
		
		return list;
	}
   
    private  List<Shangpin> getRecomment(){
		
		List<Shangpin> list=DALBase.getEntity("shangpin"," where tuijian=1 ");
		
		return list;
	}
    
    private  List<Shangpin> getNewest(){
		
		List<Shangpin> list=DALBase.getTopList("shangpin"," order by pubtime desc ",10);
		
		return list;
	}
    
        
   
	
    private  List<Shangpin> findBySpcateid(int spcid,int topcount){
		
		List<Shangpin> list=DALBase.runNativeSQL(MessageFormat.format("select  * from  shangpin where sptypeid={0} order by pubtime desc limit {1}",spcid,topcount),Shangpin.class);
		
		return list;
	}
    
    
	
	
	
}
<file_sep>/src/com/zhang/you/util/FileUploadBase.java
package com.zhang.you.util;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;

public abstract class FileUploadBase{
    protected Map<String, String> parameters = new HashMap<String, String>();// ������ͨform�?��
    
    protected String encoding = "utf-8"; // �ַ�������ȡ�ϴ��?�ĸ��ʱ���õ���encoding

    protected UploadFileFilter filter = null; // �ļ�������
    
   
    protected int sizeThreshold = DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD;

   
    protected long sizeMax = -1;

    protected File repository;
    
    public String getParameter(String key) {
        return parameters.get(key);
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }


    public long getSizeMax() {
        return sizeMax;
    }

    
    public void setSizeMax(long sizeMax) {
        this.sizeMax = sizeMax;
    }

    public int getSizeThreshold() {
        return sizeThreshold;
    }

    public void setSizeThreshold(int sizeThreshold) {
        this.sizeThreshold = sizeThreshold;
    }

   
    public File getRepository() {
        return repository;
    }

    public void setRepository(File repository) {
        this.repository = repository;
    }
    
    
    public Map<String, String> getParameters() {
        return parameters;
    }

   
    public UploadFileFilter getFilter() {
        return filter;
    }

  
    public void setFilter(UploadFileFilter filter) {
        this.filter = filter;
    }
    

    protected boolean isValidFile(FileItem item){
        return item == null || item.getName() == "" || item.getSize() == 0 || (filter != null && !filter.accept(item.getName())) ? false : true;
    }
}
 
 
 <file_sep>/WebContent/e/js/carousel.js
$(function(){
	
	$.extend($.fn,{
		
		fullCaroursel:function(){
			var $this=$(this);
			
			
			var  rollLength=$(".carousel .car-big-picture img").size();
			$this.totalLength=rollLength;
			//以下数组中的颜色与主图两边颜色同步的背景色(不同用户用脑分辨率不同导致图片无法铺满时,通过背景色的补充,起到铺满的作用)
			var rgb_arr = new Array("rgb(198, 198, 198)","rgb(238, 238, 238)","rgb(224, 232, 219)","rgb(33, 27, 123)","rgb(46, 167, 220)","rgb(0, 0, 0)");	
			
			setInterval(function(){	
				
	        	$this.css("background-color","rgb(198, 198, 198)");//第一张图的背景
				var showimageindex = $this.find(".car-big-picture img:visible").index();
				
				showimageindex=(++showimageindex)%$this.totalLength;
				//先隐藏所有小图边框
				showPicture(showimageindex);
				
			},5000);
			
			//点击左箭头
			$this.find(".car_c_inpt1").click(function(){
				
				var showindex = $this.data("showindex");	//当前选中的图片eq编号
				if(showindex <= 0){
					var showindex = rollLength-1;
				}else{
					var showindex = showindex-1;
				}
				mouseRoll(rgb_arr,title_arr,eqnum);
				
			});
			//点击右箭头
			$this.find(".car_c_inpt2").click(function(){
				var showindex = $this.data("showindex");	//当前选中的图片eq编号
				showindex=++showindex%rollLength;
				showPicture(showindex);
			});
			//鼠标滑过小图
			$this.find(".car_c_smallpic img").mouseover(function(){
				var showindex =$(".car_c_smallpic img").index($(this));
				
				showPicture(showindex);
			});
			//鼠标事件轮播方法
			showPicture=function(showindex){
				
				$this.find(".car-big-picture img").hide();	//先隐藏所有主图
				$this.find(".car_c_smallpic img").css("border","");
				$this.find(".car-big-picture img").eq(showindex).show();	//主图
				$this.css("background-color",rgb_arr[showindex]);	//主图背景
				$this.data("showindex",showindex);	//给div一个name值,代表当前自动轮到到哪张图,鼠标轮播时会用到这个值
				$this.find(".car_c_smallpic img").eq(showindex).css("border","solid 2px Darkorange");	//小图边框
				$this.find(".car_c_title p").hide().eq(showindex).show();//标题
				
			};
			
			
			
			
		}
		
	});
	$(".carousel").fullCaroursel();
	
	
    

	
});<file_sep>/src/com/zhang/you/util/Json1.java
package com.zhang.you.util;

import java.sql.Timestamp;

public class Json1{
	
	public Timestamp getTs() {
		return ts;
	}
	public void setTs(Timestamp ts) {
		this.ts = ts;
	}
	public String getTest() {
		return test;
	}
	public void setTest(String test) {
		this.test = test;
	}
	Timestamp ts;
	String test;
	
	
}<file_sep>/src/com/zhang/you/action/SpcategoryAction.java
﻿package com.zhang.you.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SQLQuery;
import org.hibernate.Query;


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.text.MessageFormat;

import com.zhang.you.bll.*;
import com.zhang.you.dal.*;
import com.zhang.you.entity.*;
import com.zhang.you.util.youUIHelper;
import com.zhang.you.util.ExtHelper;
import com.zhang.you.util.HibernateSessionFactory;
import com.zhang.you.util.PagerMetal;


public class SpcategoryAction extends PageActionBase {

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		SpcategoryTree spctree=new SpcategoryTree();
		spctree.deleteLeafNode("spcategory", new Integer(id));
		
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		String forwardurl = request.getParameter("forwardurl");
		String mingcheng = request.getParameter("mingcheng");
		String jieshao = request.getParameter("jieshao");
		String parentid=request.getParameter("parentid");
		System.out.println("获取到parentid="+parentid);
		SimpleDateFormat sdfspcategory = new SimpleDateFormat("yyyy-MM-dd");
		Spcategory spcategory = new Spcategory();
		spcategory.setIsleaf(1);
		if(parentid!=null)
		    spcategory.setParentid(new Integer(parentid));
		spcategory.setMingcheng(mingcheng == null ? "" : mingcheng);
		spcategory.setJieshao(jieshao == null ? "" : jieshao);
		
		SpcategoryTree  spctree=new SpcategoryTree();
		spctree.saveTreeNode(spcategory);
		
		binding();
	}

	
	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String forwardurl = request.getParameter("forwardurl");
		String id = request.getParameter("id");
		if (id == null)
			return;
		Spcategory spcategory = (Spcategory) DALBase.load(Spcategory.class,
				new Integer(id));
		if (spcategory == null)
			return;
		String mingcheng = request.getParameter("mingcheng");
		String jieshao = request.getParameter("jieshao");
		SimpleDateFormat sdfspcategory = new SimpleDateFormat("yyyy-MM-dd");
		spcategory.setMingcheng(mingcheng);
		spcategory.setJieshao(jieshao);
		DALBase.update(spcategory);
		
		binding();
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		
		String parentid = request.getParameter("parentid");
		if (parentid != null) {

			SpcategoryTree spct = new SpcategoryTree();
			int tempid = new Integer(parentid);
            String showtext=spct.getShowText("spcategory", tempid);
            System.out.print("showtext="+showtext);
			request.setAttribute("parenttext", showtext);
			request.setAttribute("parentid", parentid);

		} else {
			request.setAttribute("parentid", 0);
			request.setAttribute("parenttext", "商品总分类");
		}
		
		
		
		String actiontype = "save";
		dispatchParams(request, response);
		if (id != null) {
			Spcategory spcategory = (Spcategory) DALBase.load("spcategory",
					"where id=" + id);
			if (spcategory != null) {
				request.setAttribute("spcategory", spcategory);
			}
			actiontype = "update";
			request.setAttribute("id", id);
		}
		request.setAttribute("actiontype", actiontype);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/spcategoryadd.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		String filter = "where 1=1 ";
		String mingcheng = request.getParameter("mingcheng");
		if (mingcheng != null)
			filter += "  and mingcheng like '%" + mingcheng + "%'  ";
		//
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
//		if (currentpageindex != null)
//			pageindex = new Integer(currentpageindex);
//		// 设置当前页尺寸
//		if (currentpagesize != null)
//			pagesize = new Integer(currentpagesize);
		//List<Spcategory> listspcategory = DALBase.getPageEnity("spcategory",
		//		filter, pageindex, pagesize);
		SpcategoryTree  spctree=new SpcategoryTree();
		List<Spcategory> listspcategory=spctree.getTree("spcategory", 0);
		int recordscount = DALBase.getRecordCount("spcategory",
				filter == null ? "" : filter);
		request.setAttribute("listspcategory", listspcategory);
		//PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		//pm.setPagesize(pagesize);
		// 设置当前显示页
		//pm.setCurpageindex(pageindex);
		// 设置分页信息
		//request.setAttribute("pagermetal", pm);
		// 分发请求参数
		dispatchParams(request, response);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/spcategorymanager.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
<file_sep>/src/com/zhang/you/util/ExtHelper.java
package com.zhang.you.util;


import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
 * Title: Ext JS ������
 * Description: ��������ת��java����ΪXML�ļ���ʽ��JSON�ļ���ʽ
 * @author weijun
 * 
 */
public class ExtHelper {
	/**
	 * ͨ��List����XML����
	 * @param recordTotal ��¼��������һ����beanList�еļ�¼�����
	 * @param beanList ����bean����ļ���
	 * @return ���ɵ�XML����
	 */
	public static String getXmlFromList(long recordTotal , List beanList) {
		Total total = new Total();
		total.setResults(recordTotal);
		List results = new ArrayList();
		results.add(total);
		results.addAll(beanList);
		XStream sm = new XStream(new DomDriver());
		for (int i = 0; i < results.size(); i++) {
			Class c = results.get(i).getClass();
			String b = c.getName();
			String[] temp = b.split("\\.");
			sm.alias(temp[temp.length - 1], c);
		}
		String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"	+ sm.toXML(results);
		return xml;
	}
	/**
	 * ͨ��List����XML����
	 * @param beanList ����bean����ļ���
	 * @return ���ɵ�XML����
	 */
	public static String getXmlFromList(List beanList){
		return getXmlFromList(beanList.size(),beanList);
	}
	/**
	 * ͨ��List����JSON����
	 * @param recordTotal ��¼��������һ����beanList�еļ�¼�����
	 * @param beanList ����bean����ļ���
	 * @return ���ɵ�JSON����
	 */
	public static String getJsonFromList(long recordTotal , List beanList){
		TotalJson total = new TotalJson();
		total.setResults(recordTotal);
		total.setItems(beanList);
		JSONObject JsonObject = JSONObject.fromObject(total);
		return JsonObject.toString();
	}
	/**
	 * ͨ��List����JSON����
	 * @param beanList ����bean����ļ���
	 * @return ���ɵ�JSON����
	 */
	public static String getJsonFromList(List beanList){
		return getJsonFromList(beanList.size(),beanList);
	}
	/**
	 * ͨ��bean����JSON����
	 * @param bean bean����
	 * @return ���ɵ�JSON����
	 */
	public static String getJsonFromBean(Object bean){
		JSONObject JsonObject = JSONObject.fromObject(bean);
		return JsonObject.toString();
	}
}<file_sep>/README.md
## 基于javaweb的宠物商城的设计与实现

项目开始时间：5月初

项目初次完成时间：6月初

项目再次修改并完善功能：7月底

#### 介绍

本系统是采用Java技术来构建的一个基于web技术B/S结构的宠物网站，该网站建立在Spring和Struts2框架之上，前台使用JSP作为开发语言，后台使用MySQL数据库管理系统对数据进行管理，开发环境选用Eclipse，服务器采用Tomcat。

宠物商城为广大用户实现便捷的购买宠物的功能，实现宠物商店的网络化管理。网站前台系统主要负责与用户打交道，实现用户的注册、登录、宠物预览、提交订单等功能。网站后台系统主要实现管理员登录、会员中心、新闻动态、完成订单、系统维护等功能。测试结果表明，本系统能够实现所需的功能，并且运行状况良好。

#### 论文目录
本文分为六个部分。在绪论里首先分析了课题的研究背景与研究现状；第二章介绍了本系统开发采用的技术；第三章根据软件开发流程，对系统进行可行性分析和需求分析；第四章为系统概要设计，本章提出系统总体功能模块的设计，并对数据库的结构进行设计；第五章着重介绍各个功能模块的实现方案；最后，第六章介绍系统单元测试和性能测试的设计，以及对测试结果的分析。


#### 运行环境

本系统是一个web版的应用程序，需要在服务器上部署中间件Tomcat、MySQL数据库，其他的客户端通过网络进行访问该服务器即可。

（1）开发硬件平台：Windows10 x64位专业版戴尔笔记本

（2）服务器端硬件平台：Tomcat 9

（3）数据库服务器参考配置：MySQL 5.7

（4）开发工具：eclipse

#### 项目运行截图

![image-20200725213540846](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/dogbaby1.png)

![image-20200725213649312](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/dogbaby2.png)



![image-20200725213817172](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/dogbaby3.png)

![image-20200728161800209](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/image-20200728161800209.png)



![image-20200728162032045](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/image-20200728162032045.png)

![image-20200728162111006](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/image-20200728162111006.png)

#### 项目总结

本系统所实现的是一个宠物商城，主要介绍了JSP，Struts2技术。系统按照总体设计、数据库设计、各个模块设计和代码分析，宠物商品系统的基本功能已得到实现。由于时间及本人所学有限，该系统还有许多地方需要改进，并且还有许多自己未起到的功能，我们会在以后的学习过程中进一步加强和完善。

本系统具有以下优点：

1、该系统可以运行在多个Windows操作系统平台，数据库采用mysql，开发语言选择Java，可移植性好。

2、系统的用户权限进行划分，分为会员用户和管理员，不同的用户具有不同的操作权限。这不仅方便了用户，也保证了系统的安全性。

3、该系统界面简单，操作方便，容易使用。

但也存在以下缺点：

1、界面跳转复杂，接口不能被刷新，可以改进。

2、功能比较简单，没有进一步提高一些选修的程序等，不能更好的为用户提供服务。

3、数据库设计有冗余，需要进一步优化。（已优化）

## 程序使用说明

### 主要功能

宠物商城系统是宠物店日常经营管理中十分重要的一个组成部分，传统的店铺方式显得越来越局限。宠物商城系统突破了线下销售的局限,实现了线上选购,线上挑选,足不出户就可以挑选自己心仪的宠物,还可以与其他喜爱宠物的人交流。

### 操作注意事项

用户在使用《宠物商城系统》之前，应注意以下事项：

（1）本系统管理员,用户名为：admin，密码为：<PASSWORD>。

（2）本系统普通用户,用户名为：zhangyou，密码为：<PASSWORD>。

（2）在输入数字时，需要在英文状态下输入。

（3）本系统有两种操作权限，即店主与顾客等人员，店主具有所有操作权限，宠物的上架,价格的修改,利用自己的用户名与自己的密码进入不同的主界面！

### 业务流程

在用户使用本系统时，有以下各种操作：

（1）通过“用户登陆”项：可以进行顾客的登陆。

（2）通过“用户注册”项：可以进行用户注册。

（3）通过“管理员入口”项：可以进入管理员管理界面。

（4）通过“宠物资料”项：可以获取宠物喂养的教学,各种宠物的资料。

（5）通过“在线留言”项：可以查看别人的留言,登陆后还可以自己留言。

（6）通过“关于我们”项：可以查看本系统的归属,及条款。

（7）通过“我的购物车”项：登陆后可以查看自己的购物车。

（8）通过“商品信息”项：可以查看,该宠物的名称,商品编号,价格,还有立即购买选项。

（9）通过“立即购买选项”项：发现该宠物出现在购物车中,可以选择继续购物,或者提交订单。

（10）通过“提交订单”项：如无用户登陆,系统提示需要用户登陆,若有用户则支付。

（11）通过“支付”项：会提示填写订购人信息,填写订购人的姓名,电话,地址。

### 佑佑有话说

如需获取更多软件项目文档与源码，请关注我的微信公众号**【佑佑有话说】**

![](https://gitee.com/YOUYOU-xcu/images/raw/master/mini/佑佑有话说1.png)

<file_sep>/src/com/zhang/you/action/ShangpinAction.java
﻿package com.zhang.you.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.filefilter.AndFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SQLQuery;
import org.hibernate.Query;



import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.text.MessageFormat;

import com.zhang.you.bll.*;
import com.zhang.you.dal.*;
import com.zhang.you.entity.*;
import com.zhang.you.util.ExtHelper;
import com.zhang.you.util.HibernateSessionFactory;
import com.zhang.you.util.PagerMetal;


public class ShangpinAction extends PageActionBase {
	public void onLoad() {
		String actiontype = request.getParameter("actiontype");
		System.out.println("actiontype=" + actiontype);
		if (actiontype == null)
			return ;
	
		if(actiontype.equals("hasExist")){
			hasExist();
		}
		
	}

	private void hasExist() {
		String spno=request.getParameter("spno");
		String strres="true";
		if(DALBase.isExist("shangpin", "where spno='"+spno.trim()+"'")){
			strres="false";
		}else {
			
            strres="true";
		}
		try {
			System.out.println("商品编号存在性="+strres);
			response.getWriter().write(strres);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("shangpin", " where id=" + id);
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		String forwardurl = request.getParameter("forwardurl");
		String errorurl=request.getParameter("errorurl");
		String name = request.getParameter("name");
		String spno = request.getParameter("spno");
		String jiage = request.getParameter("jiage");
		String dazhe = request.getParameter("dazhe");
		String tuijian = request.getParameter("tuijian");
		String zuixin = request.getParameter("zuixin");
		String hot=request.getParameter("hot");
		String sptype = request.getParameter("sptype");
		String sptypeid = request.getParameter("sptypeid");
		String tupian = request.getParameter("tupian");
		String jieshao = request.getParameter("jieshao");
		String hyjia = request.getParameter("hyjia");
    	String pubren = request.getParameter("pubren");
		SimpleDateFormat sdfshangpin = new SimpleDateFormat("yyyy-MM-dd");
		Shangpin shangpin = new Shangpin();
		shangpin.setName(name == null ? "" : name);
		shangpin.setSpno(spno == null ? "" : spno);
		shangpin.setJiage(jiage == null ? (double) 0 : new Double(jiage));
		shangpin.setDazhe(dazhe == null ? 0 : new Integer(dazhe));
		shangpin.setTuijian(tuijian == null ? 0 : new Integer(tuijian));
		shangpin.setZuixin(zuixin == null ? 0 :new Integer( zuixin));
		shangpin.setHot(hot==null?0:new Integer(hot));
		shangpin.setSptype(sptype == null ? "" : sptype);
		shangpin.setSptypeid(sptypeid == null ? 0 : new Integer(sptypeid));
		shangpin.setTupian(tupian == null ? "" : tupian);
		shangpin.setJieshao(jieshao == null ? "" : jieshao);
		shangpin.setHyjia(hyjia == null ? 0 : new Integer(hyjia));
		
		shangpin.setPubtime(new Date());
		
		shangpin.setPubren(pubren == null ? "" : pubren);
		
		if(DALBase.isExist("shangpin", "where spno='"+spno.trim()+"'")){
			request.setAttribute("shangpin", shangpin);
			request.setAttribute("errormsg", String.format("<label class=\"error\">商品编号%1$s已经存在</label>",spno));
			
			List<Object> sptype_datasource = DALBase.getEntity("Spcategory", "");
			request.setAttribute("sptype_datasource", sptype_datasource);
			dispatchParams(request, response);
			try {
				request.getRequestDispatcher(errorurl).forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return;
		}
		
		DALBase.save(shangpin);
		
		try {
			response.sendRedirect(SystemParam.getSiteRoot()+"/admin/shangpinmanager.do?actiontype=get");
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}

	

	
	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String forwardurl = request.getParameter("forwardurl");
		String errorurl=request.getParameter("errorurl");
		String id = request.getParameter("id");
		if (id == null)
			return;
		Shangpin shangpin = (Shangpin) DALBase.load(Shangpin.class,
				new Integer(id));
		if (shangpin == null)
			return;
		String name = request.getParameter("name");
		String spno = request.getParameter("spno");
		String jiage = request.getParameter("jiage");
		String dazhe = request.getParameter("dazhe");
		String tuijian = request.getParameter("tuijian");
		String zuixin = request.getParameter("zuixin");
		String hot=request.getParameter("hot");
		String sptype = request.getParameter("sptype");
		String sptypeid = request.getParameter("sptypeid");
		String tupian = request.getParameter("tupian");
		String jieshao = request.getParameter("jieshao");
		String hyjia = request.getParameter("hyjia");
		
		String pubren = request.getParameter("pubren");
		
		shangpin.setName(name);
		shangpin.setSpno(spno);
		shangpin.setJiage(jiage == null ? (double) 0 : new Double(jiage));
		shangpin.setDazhe(dazhe == null ? 0 : new Integer(dazhe));
		shangpin.setTuijian(tuijian == null ? 0 : new Integer(tuijian));
		shangpin.setZuixin(zuixin==null?0:new Integer( zuixin));
		shangpin.setHot(hot==null?0:new Integer(hot));
		shangpin.setSptype(sptype);
		shangpin.setSptypeid(sptypeid == null ? 0 : new Integer(sptypeid));
		shangpin.setTupian(tupian);
		shangpin.setJieshao(jieshao);
		shangpin.setHyjia(hyjia == null ? 0 : new Integer(hyjia));
		
		shangpin.setPubtime(new Date() );
		
		shangpin.setPubren(pubren);
		
		DALBase.update(shangpin);
		try {
			response.sendRedirect(SystemParam.getSiteRoot()+"/admin/shangpinmanager.do?actiontype=get");
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		dispatchParams(request, response);
		if (id != null) {
			Shangpin shangpin = (Shangpin) DALBase.load("shangpin", "where id="
					+ id);
			if (shangpin != null) {
				request.setAttribute("shangpin", shangpin);
			}
			actiontype = "update";
			request.setAttribute("id", id);
		}
		request.setAttribute("actiontype", actiontype);
		List<Object> sptype_datasource = DALBase.getEntity("Spcategory", "where isleaf=1");
		request.setAttribute("sptype_datasource", sptype_datasource);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/shangpinadd.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		
		List<Object> sptype_datasource = DALBase.getEntity("Spcategory", "where isleaf=1");
		if(sptype_datasource!=null){
			Spcategory spcategory=new  Spcategory();
			spcategory.setId(-1);
			spcategory.setMingcheng("全部");
			spcategory.setIsleaf(1);
			sptype_datasource.add(spcategory);
		}
		request.setAttribute("sptype_datasource", sptype_datasource);
		String filter = "where 1=1 ";
		String spname = request.getParameter("name");
		if (spname != null)
			filter += "  and name like '%" +spname + "%'  ";
		
		String  sptype=request.getParameter("sptype");
		String  sptypeid=request.getParameter("sptypeid");
		System.out.println("sptypeid="+sptypeid);
		if(sptypeid!=null){
			if(!sptypeid.equals("-1"))
			   filter += "  and sptypeid=" +sptypeid ;
		}else
		if(sptypeid==null&&sptype_datasource.size()>0){
			
			filter+="  and sptypeid=" +((Spcategory)sptype_datasource.get(0)).getId() ;
		}
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Shangpin> listshangpin = DALBase.getPageEnity("shangpin", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("shangpin",
				filter == null ? "" : filter);
		request.setAttribute("listshangpin", listshangpin);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		
		
		// 分发请求参数
		dispatchParams(request, response);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/shangpinmanager.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
<file_sep>/src/com/zhang/you/action/DingdanAction.java
﻿package com.zhang.you.action;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.zhang.you.bll.SystemParam;
import com.zhang.you.dal.DALBase;
import com.zhang.you.entity.Attachement;
import com.zhang.you.entity.Dingdan;
import com.zhang.you.entity.Dingdanitems;
import com.zhang.you.entity.Huiyuan;
import com.zhang.you.entity.Shangpin;
import com.zhang.you.util.PagerMetal;


public class DingdanAction extends PageActionBase {
	public void onLoad() {
		String actiontype = request.getParameter("actiontype");
		System.out.println("actiontype=" + actiontype);
		if (actiontype == null)
			return ;
		
		if(actiontype.equals("modifyAmount")){
			modifyAmount();
		}
		if (actiontype.equals("shopcart")) {
			shopcart();
		}
		if (actiontype.equals("clearshopcart")) {
			clearshopcart();
		}
		if (actiontype.equals("removeShangpin")) {
			removeShangpin();
		}
		if(actiontype.equals("payfor"))
			fukuan();
		if(actiontype.equals("fahuo"))
			fahuo();
		
	}

	private void fahuo() {
		
        String ddid=request.getParameter("ddid");
		
        String fahuoren=request.getParameter("fahuoren");
        
        
		
		if(ddid!=null)
		{
			Dingdan  dingdan=(Dingdan)DALBase.load("dingdan", "where id="+ddid);
			
			dingdan.setStatus("已发货");
			dingdan.setFahuoren(fahuoren);
			dingdan.setFahuotime(new Date());
			DALBase.update(dingdan);
			
			
		}
		String forwardurl = request.getParameter("forwardurl");
	 		if (forwardurl != null)
	 			try {
	 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
	 			} catch (IOException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 	}
		
	}

	private void fukuan() {
		
		
		String ddid=request.getParameter("ddid");
		
        String accountname=request.getParameter("accountname");
       
        String  errorurl=request.getParameter("errorurl");
		
		if(ddid!=null)
		{
			Dingdan  dingdan=(Dingdan)DALBase.load("dingdan", "where id="+ddid);
			
			if(accountname!=null)
			{
		    	Huiyuan  hy=(Huiyuan)DALBase.load("huiyuan", "where accountname='"+accountname+"'");
		    	
		    	if(hy.getYue()<dingdan.getTotalprice()){
		    		
		    		request.setAttribute("errormsg", "<label class='error'>账户余额不足于支付订单,请充值</label>");
		    		try {
						request.getRequestDispatcher("/e/huiyuan/fukuan.jsp?id="+ddid).forward(request, response);
						
						return;
					} catch (ServletException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		    		
		    	}else {
					
		    		hy.setYue((float)(hy.getYue()-dingdan.getTotalprice()));
		    		hy.setJifen(hy.getJifen()+(int)dingdan.getTotalprice());
		    		DALBase.update(hy);

					dingdan.setStatus("已付款");
					DALBase.update(dingdan);
		    		request.getSession().setAttribute("huiyuan", hy);
				}
		    	
			}
			
			
		}
		String forwardurl = request.getParameter("forwardurl");
	 		if (forwardurl != null)
	 			try {
	 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
	 			} catch (IOException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 	}
		
		
		
		
		
	}

	/*
	 * 修改购物车数量
	 * */
	private void modifyAmount(){
		
		 String spid=request.getParameter("spid");
		 String shuliang=request.getParameter("shuliang");
		 List<Dingdanitems> temlist=(List<Dingdanitems>)request.getSession().getAttribute("cart");
	   	   if(temlist!=null)
	   	   {
	         for(Iterator<Dingdanitems> it= temlist.iterator();it.hasNext();)
	         {
	       	  
		       	  Dingdanitems ddi=it.next();
		       	 
		       	  if(ddi.getSpid()==new Integer(spid))
		       	  {
		       		     
		       	       ddi.setShuliang(new Integer(shuliang));
		       	       
		       	       
		       	  }
		       	  
	       	  
	         }
	   	   }
	   	   calcuateTotalfee();
	       String forwardurl = request.getParameter("forwardurl");
	 		if (forwardurl != null)
	 			try {
	 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
	 			} catch (IOException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 		}
			
	}
	
	private void removeShangpin() {
		
		
      String spid=request.getParameter("spid");
   	 
   	   List<Dingdanitems> temlist=(List<Dingdanitems>)request.getSession().getAttribute("cart");
   	   if(temlist!=null)
   	   {
         for(Iterator<Dingdanitems> it= temlist.iterator();it.hasNext();)
         {
       	  
	       	  Dingdanitems ddi=it.next();
	       	 
	       	  if(ddi.getSpid()==new Integer(spid))
	       	  {
	       		     
	       	       it.remove();
	       	       float totalfee=Float.parseFloat(request.getSession().getAttribute("totalfee").toString());
	       	       
	       	       totalfee-=ddi.getShuliang()* Float.parseFloat(ddi.getJiage());
	       	       
	       	       request.getSession().setAttribute("totalfee", totalfee);

	       			 
	       	  }
	       	  
       	  
         }
   	   }
        String forwardurl = request.getParameter("forwardurl");
 		if (forwardurl != null)
 			try {
 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
 			} catch (IOException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();
 		}
		
	}

	private void clearshopcart() {

		request.getSession().removeAttribute("cart");
		request.getSession().removeAttribute("totalfee");
		String forwardurl = request.getParameter("forwardurl");
		if (forwardurl != null)
			try {
				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}
	
	private void calcuateTotalfee()
	{
		List<Dingdanitems> cart = (List<Dingdanitems>) request.getSession()
				.getAttribute("cart");
		int totalfee=0;
		for (Dingdanitems dditem : cart) {
			totalfee += dditem.getShuliang()
					* new Double(dditem.getJiage());
		
		}
		request.getSession().setAttribute("totalfee", totalfee);

	}

	private void shopcart() {

		String forwardurl = request.getParameter("forwardurl");
		// 商品ID
		String spid = request.getParameter("spid");
		// 商品名
		String spname2 = request.getParameter("spname");
		//
		String command = request.getParameter("command");
		// request.setCharacterEncoding("UTF-8");
		float totalfee = 0;
		
		List<Dingdanitems> cart = (List<Dingdanitems>) request.getSession()
				.getAttribute("cart");

		if (spid != null) {

			if (cart == null) {

				cart = new ArrayList<Dingdanitems>();
				request.getSession().setAttribute("cart", cart);

			}
			Shangpin addshangpin = (Shangpin) DALBase.load("shangpin",
					"where id=" + spid);

			Boolean hasin = false;

			for (Dingdanitems dditem : cart) {
				System.out.println("addshangpin.getId()" + addshangpin.getId());
				System.out.println("dditem.getId()" + dditem.getId());
				if (addshangpin.getId() == dditem.getSpid()) {

					hasin = true;
					if (command!=null&&command.equals("modifyCount")) {
						String shuliang = request.getParameter("shuliang");
						dditem.setShuliang(new Integer(shuliang));
					} else
						dditem.setShuliang(dditem.getShuliang() + 1);

				}
				totalfee += dditem.getShuliang()
						* new Double(dditem.getJiage());
			}
			if (!hasin) {
				Dingdanitems temitem = new Dingdanitems();
				temitem.setSpname(addshangpin.getName());
				temitem.setSpimage(addshangpin.getTupian());
				temitem.setSpno(addshangpin.getSpno());
				temitem.setSpid(addshangpin.getId());
				temitem.setShuliang(1);
				temitem.setJiage(String.valueOf(addshangpin.getJiage()));
				totalfee += addshangpin.getJiage();
				cart.add(temitem);

			}

		}
		
		request.getSession().setAttribute("totalfee", totalfee);

		if (forwardurl != null)
			try {
				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("dingdan", " where id=" + id);
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		
	
		String shouhuodizhi = request.getParameter("shouhuodizhi");
		String shrtel = request.getParameter("shrtel");
		String shraddress = request.getParameter("shraddress");
		String shrname = request.getParameter("shrname");
		
		String des = request.getParameter("des");
		String xdren=request.getParameter("xdren");
		String status=request.getParameter("status");
		
		List<Dingdanitems> listitems=(List<Dingdanitems>)request.getSession().getAttribute("cart");
		
		if(listitems==null){
			try {
				response.sendRedirect(SystemParam.getSiteRoot()+"/e/shangpinlist.jsp");
			} catch (IOException e) {
				
				e.printStackTrace();
			}
			return;
		}
		
		
		SimpleDateFormat sdfdingdan = new SimpleDateFormat("yyyy-MM-dd");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddHHMMss");
		
		String timestamp = sdf.format(new Date());
		
		Dingdan dingdan = new Dingdan();
		dingdan.setDdno("dd"+timestamp);
		
		Double totalprice=0.0;
        for(Dingdanitems dd : listitems){
			
			dd.setDdno(dingdan.getDdno());
			dd.setDes(xdren+"购买"+dd.getSpname());
			totalprice+=Double.valueOf(dd.getJiage())*dd.getShuliang();
			
			DALBase.save(dd);
			
		}
		
		
		
		dingdan.setTitle("");
		
		dingdan.setXiadantime(new Date());
		
		dingdan.setXiadanren(xdren);
		dingdan.setTotalprice(totalprice);
		
		//dingdan.setStatus("待付款");
		dingdan.setStatus(status);
		
		dingdan.setFahuotime(new Date());
		//收货地址
		dingdan.setShouhuodizhi(shouhuodizhi);
		dingdan.setShrtel(shrtel);
		dingdan.setShraddress(shraddress);
		dingdan.setShrname(shrname);
		
		dingdan.setDes(des);
		DALBase.save(dingdan);
		
		clearshopcart();
	}

	/******************************************************
	 *********************** 内部附件支持*********************
	 *******************************************************/
	public void attachements(HttpServletRequest request,
			HttpServletResponse response, String belongid) {
		DALBase.delete("attachement", MessageFormat.format(
				" where belongid=''{0}'' and belongtable=''dingdan'' ",
				belongid));
		String[] photos = request.getParameterValues("fileuploaded");
		if (photos == null)
			return;
		for (int i = 0; i < photos.length; i++) {
			Attachement a = new Attachement();
			a.setType("images");
			a.setPubtime(new Date());
			a.setBelongfileldname("id");
			a.setFilename(photos[i]);
			a.setBelongid(belongid);
			a.setBelongtable("dingdan");
			a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
					+ a.getFilename());
			a.setTitle(a.getFilename());
			DALBase.save(a);
		}
	}



	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String forwardurl = request.getParameter("forwardurl");
		String id = request.getParameter("id");
		if (id == null)
			return;
		Dingdan dingdan = (Dingdan) DALBase
				.load(Dingdan.class, new Integer(id));
		if (dingdan == null)
			return;
		String title = request.getParameter("title");
		String ddno = request.getParameter("ddno");
		String xiadantime = request.getParameter("xiadantime");
		String xiadanren = request.getParameter("xiadanren");
		String totalprice = request.getParameter("totalprice");
		String status = request.getParameter("status");
		String fahuoren = request.getParameter("fahuoren");
		String fahuotime = request.getParameter("fahuotime");
		String shouhuodizhi = request.getParameter("shouhuodizhi");
		String shrtel = request.getParameter("shrtel");
		String shraddress = request.getParameter("shraddress");
		String shrname = request.getParameter("shrname");
		String des = request.getParameter("des");
		SimpleDateFormat sdfdingdan = new SimpleDateFormat("yyyy-MM-dd");
		dingdan.setTitle(title);
		dingdan.setDdno(ddno);
		try {
			dingdan.setXiadantime(sdfdingdan.parse(xiadantime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		dingdan.setXiadanren(xiadanren);
		dingdan.setTotalprice(totalprice == null ? (double) 0 : new Double(
				totalprice));
		dingdan.setStatus(status);
		dingdan.setFahuoren(fahuoren);
		try {
			dingdan.setFahuotime(sdfdingdan.parse(fahuotime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		dingdan.setShouhuodizhi(shouhuodizhi);
		dingdan.setShrtel(shrtel);
		dingdan.setShraddress(shraddress);
		dingdan.setShrname(shrname);
		dingdan.setDes(des);
		DALBase.update(dingdan);
		
		binding();
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		dispatchParams(request, response);
		if (id != null) {
			Dingdan dingdan = (Dingdan) DALBase.load("dingdan", "where id="
					+ id);
			if (dingdan != null) {
				request.setAttribute("dingdan", dingdan);
			}
			actiontype = "update";
			request.setAttribute("id", id);
		}
		request.setAttribute("actiontype", actiontype);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/dingdanadd.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		String filter = "where 1=1 ";
		String xdren=request.getParameter("xiadanren");
		String isurl=request.getParameter("isurl");
		if(xdren!=null)
		{
			
			if(isurl!=null&&isurl.equals("1"))
				try {
					xdren=new String(xdren.getBytes("ISO-8859-1"),"UTF-8");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			filter+=" and xiadanren='"+xdren+"'";
		}
		
		
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Dingdan> listdingdan = DALBase.getPageEnity("dingdan", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("dingdan",
				filter == null ? "" : filter);
		request.setAttribute("listdingdan", listdingdan);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		// 分发请求参数
		dispatchParams(request, response);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/dingdanmanager.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
<file_sep>/src/com/zhang/you/uibuilder/SpcategoryBuilder.java
package com.zhang.you.uibuilder;

import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;

import com.zhang.you.bll.SystemParam;
import com.zhang.you.dal.DALBase;
import com.zhang.you.entity.Shangpin;
import com.zhang.you.entity.Spcategory;

public class SpcategoryBuilder {

	
	public String BuildNavMenu(){
		
		StringBuffer sb=new StringBuffer();
		List<Spcategory> list=DALBase.getEntity("spcategory", "");
		int i=0;
		for(Iterator<Spcategory> iterator = list.iterator();iterator.hasNext();){
		   
			if(i%4==0)
				sb.append("<ul>");
			Spcategory spc=iterator.next();
			sb.append(MessageFormat.format("<li><a href=''{0}/e/shangpinlist.jsp?spcid={1}''>{2}</a></li>",SystemParam.getSiteRoot(),spc.getId(),spc.getMingcheng()));
			
			i++;
			
			if(i%4==0)
				sb.append("</ul>");
			
			
		}
		return sb.toString();
		
		
		
	}
	
	
}
