package dao;
import model.Goods;
import model.Recommend;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.*;
import utils.DataSourceUtils;
import java.sql.SQLException;
import java.util.*;
public class GoodsDao {
//select g.id,g.name,g.cover,g.price,t.name typename from recommend r,goods g,type t where type=2 and r.goods_id=g.id and g.type_id=t.id
public List<Map<String,Object>> getGoodsList(int recommendType) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql="select g.id,g.name,g.cover,g.price,t.name typename from recommend r,goods g,type t where type=? and r.goods_id=g.id and g.type_id=t.id";
return r.query(sql, new MapListHandler(),recommendType);
}
public List<Map<String,Object>> getScrollGood()throws SQLException{
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
// String sql="select g.id,g.name,g.cover,g.price from recommend r,goods g where type=1 and r.goods_id=g.id";
// return r.query(sql, new MapHandler());
String sql="select g.id,g.name,g.cover,g.price from recommend r,goods g where r.goods_id=g.id";
return r.query(sql, new MapListHandler());
}
public List<Goods> selectGoodsByTypeID(int typeID,int pageNumber,int pageSize) throws SQLException {
if(typeID==0)
{
String sql="select * from goods limit ? , ?";
QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());
return r.query(sql,new BeanListHandler<Goods>(Goods.class),(pageNumber-1)*pageSize,pageSize);
}
else
{
String sql="select * from goods where type_id=? limit ? , ?";
QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());
return r.query(sql,new BeanListHandler<Goods>(Goods.class),typeID,(pageNumber-1)*pageSize,pageSize);
}
}
public int getCountOfGoodsByTypeID(int typeID) throws SQLException {
String sql="";
QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());
if(typeID==0)
{
sql="select count(*) from goods";
return r.query(sql,new ScalarHandler<Long>()).intValue();
}
else
{
sql="select count(*) from goods where type_id=?";
return r.query(sql,new ScalarHandler<Long>(),typeID).intValue();
}
}
public List<Goods> selectGoodsbyRecommend(int type,int pageNumber,int pageSize) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
if(type==0) {
//当不添加推荐类型限制的时候
String sql = " select g.id,g.name,g.cover,g.image1,g.image2,g.intro,g.price,g.stock,t.name typename from goods g,type t where g.type_id=t.id order by g.id limit ?,?";
return r.query(sql, new BeanListHandler<Goods>(Goods.class),(pageNumber-1)*pageSize,pageSize);
}
String sql = " select g.id,g.name,g.cover,g.image1,g.image2,g.intro,g.price,g.stock,t.name typename from goods g,recommend r,type t where g.id=r.goods_id and g.type_id=t.id and r.type=? order by g.id limit ?,?";
return r.query(sql, new BeanListHandler<Goods>(Goods.class),type,(pageNumber-1)*pageSize,pageSize);
}
public int getRecommendCountOfGoodsByTypeID(int type) throws SQLException {
if(type==0)return getCountOfGoodsByTypeID(0);
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select count(*) from recommend where type=?";
return r.query(sql, new ScalarHandler<Long>(),type).intValue();
}
public Goods getGoodsById(int id) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select g.id,g.name,g.cover,g.image1,g.image2,g.price,g.intro,g.stock,t.id typeid,t.name typename from goods g,type t where g.id = ? and g.type_id=t.id";
return r.query(sql, new BeanHandler<Goods>(Goods.class),id);
}
public int getSearchCount(String keyword) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select count(*) from goods where name like ?";
return r.query(sql, new ScalarHandler<Long>(),"%"+keyword+"%").intValue();
}
public List<Goods> selectSearchGoods(String keyword, int pageNumber, int pageSize) throws SQLException{
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select * from goods where name like ? limit ?,?";
return r.query(sql, new BeanListHandler<Goods>(Goods.class),"%"+keyword+"%",(pageNumber-1)*pageSize,pageSize);
}
public boolean isScroll(Goods g) throws SQLException {
return isRecommend(g, 1);
}
public boolean isHot(Goods g) throws SQLException {
return isRecommend(g, 2);
}
public boolean isNew(Goods g) throws SQLException {
return isRecommend(g, 3);
}
private boolean isRecommend(Goods g,int type) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select * from recommend where type=? and goods_id=?";
Recommend recommend = r.query(sql, new BeanHandler<Recommend>(Recommend.class),type,g.getId());
if(recommend==null) {
return false;
}else {
return true;
}
}
public void addRecommend(int id,int type) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "insert into recommend(type,goods_id) values(?,?)";
r.update(sql,type,id);
}
public void removeRecommend(int id,int type) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "delete from recommend where type=? and goods_id=?";
r.update(sql,type,id);
}
public void insert(Goods g) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "insert into goods(name,cover,image1,image2,price,intro,stock,type_id) values(?,?,?,?,?,?,?,?)";
r.update(sql,g.getName(),g.getCover(),g.getImage1(),g.getImage2(),g.getPrice(),g.getIntro(),g.getStock(),g.getType().getId());
}
public void update(Goods g) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "update goods set name=?,cover=?,image1=?,image2=?,price=?,intro=?,stock=?,type_id=? where id=?";
r.update(sql,g.getName(),g.getCover(),g.getImage1(),g.getImage2(),g.getPrice(),g.getIntro(),g.getStock(),g.getType().getId(),g.getId());
}
public void delete(int id) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "delete from goods where id = ?";
r.update(sql,id);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
在进行实际项目开发之前,通常需要先明确项目的需求。接下来,我们将从需求分析、项目功能结构、项目预览三个方面对网上蛋糕商城项目的项目概述进行介绍,使读者对网上蛋糕商城项目的需求有一定的了解。 随着科技的发展,互联网已成为人们生活中的必需品,电子商务也变得日趋成熟起来,越来越多的商家在网上建起在线商店,给人们的生活带来了极大的便捷。网上购物系统作为B2B(Business to Business,即企业对企业)、B2C(Business to Customer,即企业对消费者)、C2C(Customer to Customer,即消费者对消费者)电子商务的前端平台,在其商务活动全过程中起着举足轻重的作用。 网上蛋糕商城项目中主要讲解如何建设B2C的网上购物系统。该项目应满足以下需求。 统一友好的操作界面,具有良好的用户体验。 商品分类详尽,可按不同类别分别查看商品信息。 可通过条幅展示推荐商品。 热销推荐和新品推荐的展示。 用户注册、验证和登录功能。 通过蛋糕名称模糊搜索相关商品。 通过购物车一次购买多件商品。 提供简单的安全模型,用户必须登录后才可以购买商品。 用户选择商品后可以在线提交
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaWeb的网上蛋糕商城平台 (389个子文件)
GoodsDao.class 7KB
GoodsDao.class 7KB
AdminGoodsEditServlet.class 6KB
AdminGoodsEditServlet.class 6KB
OrderDao.class 5KB
OrderDao.class 5KB
AdminGoodsAddServlet.class 5KB
AdminGoodsAddServlet.class 5KB
Order.class 5KB
Order.class 5KB
GoodsService.class 5KB
GoodsService.class 5KB
UserDao.class 4KB
UserDao.class 4KB
Goods.class 4KB
Goods.class 4KB
OrderService.class 4KB
OrderService.class 4KB
User.class 3KB
User.class 3KB
UserService.class 3KB
UserService.class 3KB
OrderConfirmServlet.class 3KB
OrderConfirmServlet.class 3KB
TypeDao.class 2KB
TypeDao.class 2KB
GoodsListServlet.class 2KB
GoodsListServlet.class 2KB
UserChangeAddressServlet.class 2KB
UserChangeAddressServlet.class 2KB
GoodsSearchServlet.class 2KB
GoodsSearchServlet.class 2KB
UserRegisterServlet.class 2KB
UserRegisterServlet.class 2KB
UserChangePwd.class 2KB
UserChangePwd.class 2KB
AdminGoodsListServlet.class 2KB
AdminGoodsListServlet.class 2KB
AdminUserAddServlet.class 2KB
AdminUserAddServlet.class 2KB
GoodRecommendListServlet.class 2KB
GoodRecommendListServlet.class 2KB
AdminOrderListServlet.class 2KB
AdminOrderListServlet.class 2KB
AdminUserListServlet.class 2KB
AdminUserListServlet.class 2KB
GoodsBuyServlet.class 2KB
GoodsBuyServlet.class 2KB
OrderListServlet.class 2KB
OrderListServlet.class 2KB
UserLoginServlet.class 2KB
UserLoginServlet.class 2KB
AdminUserResetServlet.class 2KB
AdminUserResetServlet.class 2KB
AdminGoodsRecommendServlet.class 2KB
AdminGoodsRecommendServlet.class 2KB
OrderItem.class 2KB
OrderItem.class 2KB
AdminUserDeleteServlet.class 2KB
AdminUserDeleteServlet.class 2KB
AdminTypeEditServlet.class 2KB
AdminTypeEditServlet.class 2KB
AdminFilter.class 2KB
AdminFilter.class 2KB
AdminTypeDeleteServlet.class 2KB
AdminTypeDeleteServlet.class 2KB
AdminTypeListServlet.class 2KB
AdminTypeListServlet.class 2KB
ApplicationListener.class 2KB
ApplicationListener.class 2KB
IndexServlet.class 2KB
IndexServlet.class 2KB
TypeService.class 2KB
TypeService.class 2KB
AdminUserEditServlet.class 2KB
AdminUserEditServlet.class 2KB
AdminGoodsEditshowServelt.class 2KB
AdminGoodsEditshowServelt.class 2KB
Page.class 2KB
Page.class 2KB
GoodsDetailServlet.class 2KB
GoodsDetailServlet.class 2KB
OrderSubmitServlet.class 2KB
OrderSubmitServlet.class 2KB
GoodsLessenServlet.class 2KB
AdminUserEditshowServlet.class 2KB
GoodsDeleteServlet.class 2KB
GoodsLessenServlet.class 2KB
GoodsDeleteServlet.class 2KB
AdminUserEditshowServlet.class 2KB
AdminOrderStatusServlet.class 2KB
AdminOrderStatusServlet.class 2KB
AdminGoodsDeleteServlet.class 2KB
AdminGoodsDeleteServlet.class 2KB
AdminTypeAddServlet.class 2KB
AdminTypeAddServlet.class 2KB
AdminOrderDeleteServlet.class 1KB
AdminOrderDeleteServlet.class 1KB
Type.class 1KB
Type.class 1KB
共 389 条
- 1
- 2
- 3
- 4
资源评论
笔触狂放
- 粉丝: 6108
- 资源: 99
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- PySpark和Matplotlib绘制趋势图的简单示例.rar
- 实验5 用例图.docx
- 课程大作业基于python实现的单目双目视觉三维重建源码(95分以上).zip
- 使用matplotlib库绘制简单图表的例子.rar
- 九阴真经OL资源解包工具
- python-leetcode面试题解之第307题区域和检索.zip
- python-leetcode面试题解之第305题岛屿数量II.zip
- python-leetcode面试题解之第304题二维区域和检索.zip
- python-leetcode面试题解之第303题区域和检索.zip
- python-leetcode面试题解之第299题猜数字游戏.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功