package com.tarena.dangdang.dao.impl;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tarena.dangdang.dao.Pagination;
import com.tarena.dangdang.dao.ProductDao;
import com.tarena.dangdang.entity.Book;
import com.tarena.dangdang.entity.Product;
public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
// private static final String S_CDESC = "";
private static final String CID_DEFUALT = "from Book b join fetch b.category c where c.id=? order by b.id";
private static final String PRICEASC = "from Book b join fetch b.category c where c.id=? order by b.dangPrice asc";
private static final String PRICEDESC = "from Book b join fetch b.category c where c.id=? order by b.dangPrice desc";
private static final String P_TASC = "from Book b join fetch b.category c where c.id=? order by b.publishTime asc";
private static final String P_TDESC = "from Book b join fetch b.category c where c.id=? order by b.publishTime desc";
private static final String A_TDESC = "from Book b join fetch b.category c where c.id=? order by b.addTime desc";
private static final String A_TASC = "from Book b join fetch b.category c where c.id=? order by b.addTime asc";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static final String PCID_DEFUALT = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.id";
private static final String P_PRICEASC = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.dangPrice asc";
private static final String P_PRICEDESC = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.dangPrice desc";
private static final String P_P_TASC = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.publishTime asc";
private static final String P_P_TDESC = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.publishTime desc";
private static final String P_A_TDESC = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.addTime desc";
private static final String P_A_TASC = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.addTime asc";
@SuppressWarnings("unchecked")
public List<Product> findByCategoryId(Integer cid, Pagination p)
throws Exception {
String hql = CID_DEFUALT;
if (p.getType().equals("IDASC")) {
System.out.println("根据ID升序");
hql = CID_DEFUALT;
} else if (p.getType().equals("PRICEASC")) {
System.out.println("根据价格升序");
hql = PRICEASC;
} else if (p.getType().equals("PRICEDESC")) {
System.out.println("根据价格降序");
hql = PRICEDESC;
}else if(p.getType().equals("P_TDESC")) {
System.out.println("根据出版时间降序");
hql = P_TDESC;
}else if(p.getType().equals("P_TASC")) {
System.out.println("根据出版时间升序");
hql = P_TASC;
}else if(p.getType().equals("A_TDESC")) {
System.out.println("根据上架时间降序");
hql = A_TDESC;
}else if(p.getType().equals("A_TASC")) {
System.out.println("根据上架时间升序");
hql = A_TASC;
}else if(p.getType().equals("S_CDESC")) {
System.out.println("根据上架时间降序");
hql = CID_DEFUALT;
}
Query q = this.getSession().createQuery(hql).setInteger(0, cid);
q.setFirstResult((p.getPage() - 1) * p.getPageSize());
q.setMaxResults(p.getPageSize());
return q.setCacheable(true).list();
}
public Number getCountByCategoryId(Integer cid, Pagination p)
throws Exception {
String hql = "select count(*) from Book b join b.category c where c.id=:id";
return (Number) this.getSession().createQuery(hql).setInteger("id", cid)
.uniqueResult();
}
private static final String PCID_DEFAULT = "from Book b join fetch b.category c where c.parentCategory.id=? order by b.id ";
@SuppressWarnings("unchecked")
public List<Product> findByParantCategoryId(Integer pcid, Pagination p)
throws Exception {
String hql = PCID_DEFUALT;
if (p.getType().equals("IDASC")) {
System.out.println("根据ID升序");
hql = PCID_DEFAULT;
} else if (p.getType().equals("PRICEASC")) {
System.out.println("根据价格升序");
hql = P_PRICEASC;
} else if (p.getType().equals("PRICEDESC")) {
System.out.println("根据价格降序");
hql = P_PRICEDESC;
}else if(p.getType().equals("P_TDESC")) {
System.out.println("根据出版时间降序");
hql = P_P_TDESC;
}else if(p.getType().equals("P_TASC")) {
System.out.println("根据出版时间升序");
hql = P_P_TASC;
}else if(p.getType().equals("A_TDESC")) {
hql = P_A_TDESC;
}else if(p.getType().equals("A_TASC")) {
hql = P_A_TASC;
}else if(p.getType().equals("S_CDESC")) {
hql = PCID_DEFAULT;
}
Query q = this.getSession().createQuery(hql).setInteger(0, pcid);
q.setFirstResult((p.getPage() - 1) * p.getPageSize());
q.setMaxResults(p.getPageSize());
return q.setCacheable(true).list();
}
public Number getCountByParentCategoryId(Integer pcid, Pagination p)
throws Exception {
String hql = "select count(*) from Book b join b.category c where c.parentCategory.id=:id";
return (Number) this.getSession().createQuery(hql).setInteger("id", pcid)
.uniqueResult();
}
public Product findProductById(Integer id) throws Exception {
return (Product) this.getHibernateTemplate().get(Book.class, id);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ssh电子商务demo项目
共602个文件
gif:254个
jpg:71个
class:62个
4星 · 超过85%的资源 需积分: 13 104 下载量 119 浏览量
2012-03-19
13:19:25
上传
评论 1
收藏 14.57MB ZIP 举报
温馨提示
该demo小项目运用了ssh,实现了电子商城的核心功能,包括购物车、分页浏览、注册登录等,适合刚学ssh框架的朋友。框架式struts2.18、hibernate3.32,spring 2.56.
资源推荐
资源详情
资源评论
收起资源包目录
ssh电子商务demo项目 (602个子文件)
CartServiceImpl.class 6KB
ProductDaoImpl.class 6KB
OrderCompletedAction.class 6KB
RegistOneAction.class 5KB
User.class 5KB
Order.class 4KB
OrderInfoAction.class 4KB
BookListAction.class 4KB
ValidateCodeAction.class 4KB
Book.class 4KB
Comment.class 3KB
Product.class 3KB
CategoryAction.class 3KB
Category.class 3KB
RecoveryAddressAction.class 3KB
LoginAction.class 3KB
ListAction.class 3KB
BaseAction.class 3KB
CartAddAction.class 3KB
CartRemovedListAction.class 3KB
ReceiveAddress.class 3KB
CartBuyedListAction.class 3KB
OrderDaoImpl.class 3KB
ProductServiceImpl.class 3KB
RegistTwoAction.class 3KB
CategoryDaoImpl.class 2KB
UserServiceImpl.class 2KB
CommentReply.class 2KB
AddressFormAction.class 2KB
CategoryServiceImpl.class 2KB
OrderServiceImpl.class 2KB
CookieUtil.class 2KB
CartUpdateAction.class 2KB
UserDaoImpl.class 2KB
Item.class 2KB
Pagination.class 2KB
CartRevoveryAction.class 2KB
CartDeleteAction.class 2KB
SendWay.class 2KB
LoginInfoAction.class 2KB
CategoryListAction.class 2KB
BookDetailAction.class 2KB
CartItem.class 1KB
CartFactory.class 1KB
MD5.class 1KB
LogoutAction.class 1KB
ShowCartAction.class 976B
OrderService.class 930B
OrderDao.class 918B
UUID.class 880B
EmailUtil.class 795B
ProductService.class 745B
CartService.class 743B
ProductDao.class 723B
UserService.class 611B
RecommendAction.class 583B
CategoryDao.class 567B
NewAction.class 565B
HotAction.class 565B
Constant.class 508B
CategoryService.class 500B
UserDao.class 497B
.classpath 3KB
book.css 25KB
second.css 20KB
register_login.css 14KB
book_head090107.css 13KB
login.css 13KB
book1.css 11KB
comm_answer.css 10KB
list.css 10KB
shopping_vehicle.css 9KB
shopping_head.css 5KB
booksaleslist.css 5KB
page_bottom.css 3KB
public_footer.css 2KB
research.css 2KB
product_exp.css 1KB
secBook_Show.css 1KB
navi.css 1KB
pubsug090107.css 555B
ancz081216_button05.gif 25KB
xssj_banner.gif 8KB
d_introduce.gif 5KB
cheap4.gif 4KB
cheap3.gif 4KB
cheap2.gif 4KB
cheap1.gif 3KB
06baihuo_daohang_08.gif 3KB
logo.gif 3KB
logo.gif 3KB
window_loading.gif 2KB
book_logo.gif 2KB
back_window.gif 2KB
title_bg.gif 2KB
pic_myshopping.gif 2KB
butt_balance.gif 2KB
button_write_comm.gif 2KB
ddb_1.gif 2KB
label3.gif 1KB
共 602 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
lennon1908
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页