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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于jsp+servlet+mysql网上蛋糕店-idea版
共419个文件
class:112个
jpg:82个
jsp:58个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 189 浏览量
2023-01-08
10:19:23
上传
评论 2
收藏 24.75MB RAR 举报
温馨提示
一、系统介绍 系统主要功能: 客户:主页、用户登陆、用户注册、个人中心、我的购物车、我的订单 系统管理员:订单管理、客户管理、商品管理、类目管理 详见:https://blog.csdn.net/qq_33037637/article/details/124970106
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp+servlet+mysql网上蛋糕店-idea版 (419个子文件)
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
AdminUserEditshowServlet.class 2KB
GoodsLessenServlet.class 2KB
GoodsDeleteServlet.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
共 419 条
- 1
- 2
- 3
- 4
- 5
资源评论
五星资源
- 粉丝: 7178
- 资源: 5490
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- OpenFOAM 二维圆柱体周围的涡流脱落
- Unity有哪些流行的游戏案例?
- 708946149858210笔记.zip
- Segment Anything Model 2(SAM 2)分割大模型预训练权重sam2.1-hiera-tiny.pt
- java行为分析系统源码带本地搭建教程数据库 MySQL源码类型 WebForm
- 【java毕业设计】游戏交易系统源码(springboot+vue+mysql+说明文档+LW).zip
- Django开发的Redis管理平台Repoll,旨在提高企业对redis实例平台化管理,助力运维转型
- 【java毕业设计】疫情信息管理系统源码(springboot+vue+mysql+说明文档+LW).zip
- 13章完结Electron+Vue3+AI+云存储-实战跨平台桌面应用
- SAM2(Segment Anything2)预训练权重sam2.1-hiera-base-plus.pt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功