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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
在线蛋糕商城的设计与实现【完整源代码】
共402个文件
class:112个
jpg:82个
jsp:58个
需积分: 0 2 下载量 54 浏览量
2024-10-05
17:37:46
上传
评论 1
收藏 23.95MB ZIP 举报
温馨提示
本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台; 管理员角色包含以下功能: 管理员登录 商品管理 订单管理 客户管理 类目管理等功能。 用户角色包含以下功能: 首页 商品分类 热销和新品 注册新用户 用户登录 查看个人中心 购买商品 查看购物车 提交订单 模拟支付成功 查看订单等功能。 ==========================以下内容占位================ JSP+CSS+jQuery+bootstrap+mysql+servletJSP+CSS+jQuery+bootstrap+mysql+servletJSP+CSS+jQuery+bootstrap+mysql+servletJSP+CSS+jQuery+bootstrap+mysql+servletJSP+CSS+jQuery+bootstrap+mysql+servletJSP+CSS+jQuery+bootstrap+mysql+servletJSP+CSS+jQuery+bootstrap+mysql+servletJSP+CS
资源推荐
资源详情
资源评论
收起资源包目录
在线蛋糕商城的设计与实现【完整源代码】 (402个子文件)
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
AdminUserEditshowServlet.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
共 402 条
- 1
- 2
- 3
- 4
- 5
资源评论
ai安歌
- 粉丝: 6223
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python与mysql基础.txt
- maven上传工具,仅限windows环境
- 【java毕业设计】酒店管理系统源码(springboot+vue+mysql+说明文档+LW).zip
- influxdb2-2.7.10-windows
- 【java毕业设计】教师人事档案管理系统源码(springboot+vue+mysql+说明文档+LW).zip
- TensorFlow Core基本分类:对服装图像进行分类.pdf
- C# 操作SQLServer 的增删改查案例.zip
- influxStuido-0.2.0.0-Release
- 【java毕业设计】交流互动系统源码(springboot+vue+mysql+说明文档+LW).zip
- 网络安全领域的Web漏洞分析与防御技术探讨
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功