package org.dxc.market.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.dxc.market.entity.Book;
import org.dxc.market.entity.Food;
import org.dxc.market.entity.Product;
import org.dxc.market.entity.Recommend;
import org.dxc.market.util.DBUtil;
public class JdbcProductDAO implements ProductDAO {
private static final String findnew ="select * from d_product where has_deleted=0 order by add_time desc limit 0,?";
private static final String findrecommend =
"select p.id,p.product_name,p.description,p.fixed_price,p.dang_price,p.product_pic,b.author,b.publishing,b.publish_time"+
" from d_product p join d_book b on p.id=b.id where p.has_deleted=0 order by rand() limit 2";
private static final String findBooksByCatId =
"select dp.*,db.* " +
"from d_category_product dcp " +
"join d_product dp on (dcp.product_id=dp.id) " +
"join d_book db on(dp.id=db.id) " +
"where dcp.cat_id=? and dp.has_deleted=0 " +
"limit ?,?";
private static final String findHotsale="select * from d_item i join d_product p on i.product_id=p.id group by i.product_id order by sum(i.product_num) desc limit 4";
private static final String fingById="select * from d_product where has_deleted=0 and id=?";
private static final String findNewHot="select *,sum(i.product_num) as num from d_item i join d_product p on i.product_id=p.id where p.has_deleted=0 group by i.product_id order by sum(i.product_num) desc,p.add_time desc limit 8";
private static final String findCountAll="select count(*) from d_product where has_deleted=0";
private static final String BooksOrdeyByAddtimeASC = "select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_book db on(dp.id=db.id) "
+ " where dcp.cat_id=? and dp.has_deleted=0 "
+ " order by dp.add_time asc limit ?,?";
private static final String BooksOrdeyByAddtimeDESC = "select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_book db on(dp.id=db.id) "
+ " where dcp.cat_id=? and dp.has_deleted=0 "
+ " order by dp.add_time desc limit ?,?";
private static String findAllProduct ="select * from d_product where has_deleted=0 limit ?,?";
private static String delProductById="update d_product set has_deleted=1 where id=?";
private static String findByProductId="select * from d_Product dp join d_book db on dp.id=db.id where dp.id=? and dp.has_deleted=0 ";
private static String findFoodById="select * from d_Product dp join d_food df on dp.id=df.id where dp.id=? and dp.has_deleted=0 ";
private static final String BooksOrdeyBySaleDESC = "select * from d_item di join (select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_book db on(dp.id=db.id) "
+ " where dcp.cat_id=? ) dpb on (di.product_id=db.id) " +
"where dp.has_deleted=0 "
+ " order by sum(di.product_num) desc limit ?,?";
private static final String BooksOrdeyByPricetimeASC = "select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_book db on(dp.id=db.id) "
+ " where dcp.cat_id=? and dp.has_deleted=0 "
+ " order by dp.dang_price asc limit ?,?";
private static final String search="select * from d_product where has_deleted=0 and product_name like ?";
private static final String findFoodsByCatId =
"select dp.*,db.* " +
"from d_category_product dcp " +
"join d_product dp on (dcp.product_id=dp.id) " +
"join d_food db on(dp.id=db.id) " +
"where dcp.cat_id=? and dp.has_deleted=0 " +
"limit ?,?";
private static final String FoodsOrdeyByAddtimeASC = "select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_food db on(dp.id=db.id) "
+ " where dcp.cat_id=? and dp.has_deleted=0 "
+ " order by dp.add_time asc limit ?,?";
private static final String FoodsOrdeyByAddtimeDESC = "select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_food db on(dp.id=db.id) "
+ " where dcp.cat_id=? and dp.has_deleted=0 "
+ " order by dp.add_time desc limit ?,?";
private static final String FoodsOrdeyBySaleDESC = "select * from d_item di join (select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_food db on(dp.id=db.id) "
+ " where dcp.cat_id=? ) dpb on (di.product_id=db.id) "+
"where dp.has_deleted=0 "
+ " order by sum(di.product_num) desc limit ?,?";
private static final String FoodsOrdeyByPricetimeASC = "select dp.*,db.* "
+ "from d_category_product dcp "
+ " join d_product dp on(dcp.product_id = dp.id) "
+ " join d_food db on(dp.id=db.id) "
+ " where dcp.cat_id=? and dp.has_deleted=0 "
+ " order by dp.dang_price asc limit ?,?";
//查找最新商品
public List<Product> findNew(int size) throws Exception {
List<Product> lists=new ArrayList<Product>();
Connection conn=DBUtil.getConnection();
PreparedStatement prep=conn.prepareStatement(findnew);
prep.setInt(1, size);
ResultSet rst=prep.executeQuery();
while(rst.next()){
Product pro=new Product();
pro.setId(rst.getInt("id"));
pro.setProductName(rst.getString("product_name"));
pro.setDescription(rst.getString("description"));
pro.setAddTime(rst.getLong("add_time"));
pro.setFixedPrice(rst.getDouble("fixed_price"));
pro.setDangPrice(rst.getDouble("dang_price"));
pro.setKeywords(rst.getString("keywords"));
pro.setHasDeleted(rst.getInt("has_deleted"));
pro.setProductPic(rst.getString("product_pic"));
lists.add(pro);
}
DBUtil.closeConnection();
return lists;
}
//查找推荐商品
public List<Recommend> findRecommend() throws Exception {
List<Recommend> lists=new ArrayList<Recommend>();
Connection conn=DBUtil.getConnection();
PreparedStatement prep=conn.prepareStatement(findrecommend);
ResultSet rst=prep.executeQuery();
while(rst.next()){
Recommend rec=new Recommend();
rec.setId(rst.getInt("id"));
rec.setProductName(rst.getString("product_name"));
rec.setAuthor(rst.getString("author"));
rec.setDescription(rst.getString("description"));
rec.setPublishing(rst.getString("publishing"));
rec.setPublishTime(rst.getLong("publish_time"));
rec.setFixedPrice(rst.getDouble("fixed_price"));
rec.setDangPrice(rst.getDouble("dang_price"));
rec.setProductPic(rst.getString("product_pic"));
//System.out.println(rec.getFixedPrice());
lists.add(rec);
}
DBUtil.closeConnection();
return lists;
}
//通过cid查找商品
public List<Book> findBooksByCatid(int cid,int page,int pageSize) throws Exception {
Connection conn = DBUtil.getConnection();
PreparedStatement prep =
conn.prepareStatement(findBooksByCatId);
prep.setInt(1, cid);
int begin = (page-1)*pageSize;
prep.setInt(2, begin);
prep.setInt(3, pageSize);
ResultSet rs = prep.executeQuery();
List<Book> lists = new ArrayList<Book>();
while(rs.next()){
Book pro = new Book();
pro.setId(rs.getInt("id"));
pro.setProductName(rs.getString("product_name"));
pro.setDescription(rs.getString("description"));
pro.setAddTime(rs.getLong("add_time"));
pro.setFixedPrice(rs.getDouble("fixed_price"));
pro.setDangPrice(rs.getDouble("dang_price"));
pro.setKeywords(rs.getString("keywords"));
pro.setHasDeleted(rs.getInt("has_deleted"));
pro.setProductPic(rs.getString("product_pic"));
pro.setAuthor(rs.getString("author"));
p
没有合适的资源?快使用搜索试试~ 我知道了~
网上超市系统,模拟当当网界面,网店系统,有订单、商品分类展示功能

共647个文件
gif:231个
class:97个
java:97个

需积分: 9 117 浏览量
2014-11-09
00:38:42
上传
评论 1
收藏 6.54MB RAR 举报
温馨提示
这是个网上超市系统,模拟当当网实现,有订单处理。商品分类展示等功能。采用mysql+myeclipse+ssh实现,内含sql脚本,装好环境,执行sql脚本后启动项目可成功运行
资源推荐
资源详情
资源评论











收起资源包目录





































































































共 647 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论


cowyouboy
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制
