** 检测登录帐号是否有效 *
public boolean chkLoginName(String loginName) throws Exception {
Session session = MySessionFactory.getSession(); Transaction tx = null; boolean result = true; try{
String .createQuery(.beginTransaction();
if (((Integer)query.uniqueResult()).intValue()>0)result=false; txmit();
}catch(Exception ex){
if(tx!=null)tx.rollback();
logger.info(\在执行MemServiceImpl类中的chkLoginName方法时出错:
\\n\
}
ex.printStackTrace();
}finally{ }
MySessionFactory.closeSession(); return result;
用户注册模块运行图如下图8所示:
图8用户注册模块运行图
⑵购物车模块关键代码
public class CartServiceImpl extends BaseLog implements CartService { ** 选购商品 *
public boolean addCart(Member member, Merchandise mer, int number) throws Exception {
Session session = MySessionFactory.getSession();
Transaction tx = null;
boolean status = false; try{ Cartselectedmer sel = null;
int
favourable
member.getMemberlevel().getFavourable().intValue();
判断该会员是否已经有使用中的购物车 String .createQuery(.beginTransaction(); Cart cart = (Cart)query.uniqueResult(); if (cart==null){ cart = new Cart();
cart.setCartStatus(new Integer(0));
cart.setMember(member);
cart.setMoney(Double.valueOf(number*mer.getPrice().doubleValue())); cart.getMerchandises().add(mer);
session.save(cart);
}else{
如果选购的是已经选购过的商品则只增加商品数量即可
. . . . . . .
** 更新购物车 *
public boolean updateCart(Cart cart) throws Exception {
Session session = MySessionFactory.getSession();
=
Transaction tx = null; boolean status = false; try{
tx = session.beginTransaction(); session.update(cart); txmit(); status = true;
}catch(Exception ex){
if(tx!=null)tx.rollback();
logger.info(\在执行CartServiceImpl类中的updateCart方法时出错:
\\n\ }
购物车模块运行图如下图9所示:
}
ex.printStackTrace();
}finally{ }
MySessionFactory.closeSession(); return status;
图9购物车模块运行图
⑶订单模块代码
public class OrderServiceImpl extends BaseLog implements OrderService {
** 新增订单 *
public boolean addOrder(Orders order) throws Exception {
Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{
tx = session.beginTransaction(); session.save(order); txmit(); status=true;
}catch(Exception ex){
if(tx!=null)tx.rollback();
logger.info(\在执行OrderServiceImpl类中的addOrder方法时出
错:\\n\
}
ex.printStackTrace();
}finally{ }
MySessionFactory.closeSession();
return status;
………
** 修改订单 *
public boolean updateOrder(Orders order) throws Exception {
Session session = MySessionFactory.getSession(); Transaction tx = null; boolean status = false; try{
tx = session.beginTransaction(); session.update(order); txmit(); status=true;
}catch(Exception ex){
if(tx!=null)tx.rollback();
logger.info(\在执行OrderServiceImpl类中的updateOrder方法时
出错:\\n\ }
订单模块运行图如下图10所示:
}
ex.printStackTrace();
}finally{ }
MySessionFactory.closeSession();
return status;
相关推荐: