你的位置:首页 > Java教程

[Java教程]网上商城5


1.创建表

商品表:CREATE TABLE `product` ( `pid` int(11) NOT NULL AUTO_INCREMENT, `pname` varchar(255) DEFAULT NULL, `market_price` double DEFAULT NULL, `shop_price` double DEFAULT NULL, `image` varchar(255) DEFAULT NULL, `num` int(11) DEFAULT NULL, `pdesc` varchar(255) DEFAULT NULL, `is_hot` int(11) DEFAULT NULL, `pdate` datetime DEFAULT NULL, `csid` int(11) DEFAULT NULL, PRIMARY KEY (`pid`), KEY `FKED8DCCEFB9B74E02` (`csid`), CONSTRAINT `FKED8DCCEFB9B74E02` FOREIGN KEY (`csid`) REFERENCES `categorysecond` (`csid`)) ENGINE=InnoDB AUTO_INCREMENT=74 DEFAULT CHARSET=utf8;INSERT INTO `product` VALUES ('1', '韩版连帽加厚毛衣女外套', '558', '228', 'products/1/cs10001.jpg', '200', '双11限量200件,拍完下架,加车享优惠,早下手早发货。。秋冬个性中长款毛衣,美丽和温度同在!限量供应,拒绝撞衫!迫于纱线和人工在不断上涨的双重压力下,产品涨价在即!少量现货出售中,手快有,手慢等哦,赶紧抢哦,绝对高大上。', '1', '2014-11-02 20:18:00', '1');

 

2.查询首页上热门商品

/** * 查询热门商品: * */public List<Product> findByHot() {	List<Product> list = this.getHibernateTemplate().executeFind(			new PageHibernateCallback<Product>(					"from Product where is_hot=? order by pdate desc",					new Object[] { 1 }, 0, 10));	if (list.size() > 0) {		return list;	}	return null;}

 

<s:iterator value="hList">		<li>			<a href="${ pageContext.request.contextPath }/product_findByPid.action?pid=<s:property value="pid"/>" target="_blank"><img image"/>" src="http://storage.shopxx.net/demo-image/3.0/201301/0ff130db-0a1b-4b8d-a918-ed9016317009-thumbnail.jpg" /></a>		</li></s:iterator>	

  

3.查询首页上最新商品

/** * 查询最新商品: */public List<Product> findByNew() {	/*	 * List<Product> list = this.getHibernateTemplate().executeFind( new	 * PageHibernateCallback<Product>( "from Product order by pdate desc",	 * null, 0, 10));	 */	DetachedCriteria criteria = DetachedCriteria.forClass(Product.class);	// 按日期排序:	criteria.addOrder(Order.desc("pdate"));	List<Product> list = this.getHibernateTemplate().findByCriteria(			criteria, 0, 10);	if (list.size() > 0) {		return list;	}	return null;}