赞
踩
* 1\. 模块设计
项目分享:见文末!
会员子系统主要包括会员注册(系统必须,几乎每个系统都有)、购物车(一般买到的东西可以放购物车和直接付钱,这里本系统是统一放购物车)、顾客留言(供用户发表言论的地方)、商品浏览(本系统的主要功能也是系统的首页也是商务网站永恒的信仰,太常见了)、订单管理(查询用户自身所买东西的地方)、修改注册资料。会员子系统
部分代码示例:
package com.itbaizhan.service;
import java.util.List; import org.hibernate.*; import com.itbaizhan.ORM.*; import com.itbaizhan.base.BaseLog; /** ��Ʒ���ࡢ��Ʒ���ؼ���Ʒҵ��������ӿ�ʵ�� */ public class MerServiceImpl extends BaseLog implements MerService { /** ������Ʒ���� */ public boolean addCategory(Category cate) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{ tx = session.beginTransaction(); session.save(cate); tx.commit(); status = true; }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�addCategory����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return status; } /** �����Ʒ���� */ public List browseCategory() throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; List list = null; try{ Query query = session.createQuery("from Category as a order by a.id"); tx = session.beginTransaction(); list = query.list(); tx.commit(); if (!Hibernate.isInitialized(list))Hibernate.initialize(list); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�browseCategory����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return list; } /** ɾ��ָ������Ʒ���� */ public boolean delCategory(Integer id) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{ tx = session.beginTransaction(); Category cate = (Category)session.load(Category.class, id); session.delete(cate); tx.commit(); status = true; }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�delCategory����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return status; } /** װ��ָ������Ʒ���� */ public Category loadCategory(Integer id) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; Category cate = null; try{ tx = session.beginTransaction(); cate = (Category)session.get(Category.class, id); tx.commit(); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�loadCategory����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return cate; } /** ������Ʒ���� */ public boolean updateCategory(Category cate) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{ tx = session.beginTransaction(); session.update(cate); tx.commit(); status = true; }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�updateCategory����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return status; } /** ������Ʒ */ public boolean addMer(Merchandise mer) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{ tx = session.beginTransaction(); session.save(mer); tx.commit(); status = true; }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�addMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return status; } /** �����Ʒ */ public List browseMer(String hql) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; List list = null; try{ Query query = session.createQuery(hql); tx = session.beginTransaction(); list = query.list(); tx.commit(); if (!Hibernate.isInitialized(list))Hibernate.initialize(list); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�browseMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return list; } /** ɾ��ָ������Ʒ */ public boolean delMer(Integer id) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{ tx = session.beginTransaction(); Merchandise mer = (Merchandise)session.load(Merchandise.class, id); session.delete(mer); tx.commit(); status = true; }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�delMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return status; } /** װ��ָ������Ʒ */ public Merchandise loadMer(Integer id) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; Merchandise mer = null; try{ tx = session.beginTransaction(); mer = (Merchandise)session.get(Merchandise.class, id); tx.commit(); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�loadMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return mer; } /** ������Ʒ */ public boolean updateMer(Merchandise mer) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{ tx = session.beginTransaction(); session.update(mer); tx.commit(); status = true; }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�updateMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return status; } /** ��ҳ�����Ʒ */ public List browseMer(int pageSize, int pageNo, int cateId,boolean isSpecial) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; List list = null; try{ String hql = "from Merchandise as a"; if (isSpecial){ //�ؼ���Ʒ hql = hql + " where a.special=1"; }else{ //��ͨ��Ʒ hql = hql + " where a.special=0"; } if (cateId!=0){ //ָ����� hql = hql + " and a.category.id="+cateId; } hql = hql + " order by a.id desc"; Query query = session.createQuery(hql); query.setMaxResults(pageSize); query.setFirstResult((pageNo-1)*pageSize); tx = session.beginTransaction(); list = query.list(); tx.commit(); if (!Hibernate.isInitialized(list))Hibernate.initialize(list); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�browseMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return list; } /** ������Ʒ */ public List browseMer(int pageSize, int pageNo, String hql) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; List list = null; try{ Query query = session.createQuery(hql); query.setMaxResults(pageSize); query.setFirstResult((pageNo-1)*pageSize); tx = session.beginTransaction(); list = query.list(); tx.commit(); if (!Hibernate.isInitialized(list))Hibernate.initialize(list); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�browseMer����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return list; } /** ͳ�Ƽ�¼���� */ public int countRecord(String hql) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; int count = 0; try{ tx = session.beginTransaction(); Query query = session.createQuery(hql); query.setMaxResults(1); count = ((Integer)query.uniqueResult()).intValue(); tx.commit(); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("��ִ��MerServiceImpl���е�countRecord����ʱ���?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return count; } }
项目分享:见文末!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。