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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
javaweb2源代码.rar
共1008个文件
class:267个
jsp:197个
java:140个
需积分: 9 0 下载量 183 浏览量
2022-09-19
23:02:52
上传
评论
收藏 43.11MB RAR 举报
温馨提示
javaweb2源代码.rar
资源详情
资源评论
资源推荐
收起资源包目录
javaweb2源代码.rar (1008个子文件)
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
$CACHE_FILE$ 589B
GoodsDao.class 7KB
GoodsDao.class 7KB
AdminGoodsEditServlet.class 6KB
AdminGoodsEditServlet.class 6KB
OrderDao.class 5KB
OrderDao.class 5KB
UsersDao.class 5KB
UsersDao.class 5KB
AdminGoodsAddServlet.class 5KB
AdminGoodsAddServlet.class 5KB
Order.class 5KB
Order.class 5KB
UploadServlet.class 5KB
UploadServlet.class 5KB
GoodsService.class 5KB
GoodsService.class 5KB
UserDao.class 4KB
UserDao.class 4KB
RegistServlet.class 4KB
RegistServlet.class 4KB
Goods.class 4KB
Goods.class 4KB
LoginServlet.class 4KB
LoginServlet.class 4KB
OrderService.class 4KB
OrderService.class 4KB
RequestLineServlet.class 3KB
RequestLineServlet.class 3KB
User.class 3KB
User.class 3KB
LastAccessServlet.class 3KB
LastAccessServlet.class 3KB
Example01.class 3KB
Example01.class 3KB
ControllerServlet.class 3KB
ControllerServlet.class 3KB
LoginServlet.class 3KB
LoginServlet.class 3KB
UserService.class 3KB
UserService.class 3KB
ConnDB.class 3KB
ConnDB.class 3KB
Example03.class 3KB
Example03.class 3KB
RegisterFormBean.class 3KB
RegisterFormBean.class 3KB
OrderConfirmServlet.class 3KB
OrderConfirmServlet.class 3KB
AutoLoginFilter.class 2KB
AutoLoginFilter.class 2KB
PurchaseServlet.class 2KB
PurchaseServlet.class 2KB
TestServlet04.class 2KB
TestServlet04.class 2KB
TypeDao.class 2KB
TypeDao.class 2KB
GoodsListServlet.class 2KB
GoodsListServlet.class 2KB
DownloadServlet.class 2KB
DownloadServlet.class 2KB
IndexServlet.class 2KB
IndexServlet.class 2KB
UserChangeAddressServlet.class 2KB
UserChangeAddressServlet.class 2KB
CartServlet.class 2KB
CartServlet.class 2KB
GoodsSearchServlet.class 2KB
GoodsSearchServlet.class 2KB
RequestHeadersServlet.class 2KB
RequestHeadersServlet.class 2KB
RequestParamsServlet.class 2KB
RequestParamsServlet.class 2KB
UserRegisterServlet.class 2KB
UserRegisterServlet.class 2KB
TestServlet07.class 2KB
TestServlet07.class 2KB
Example02.class 2KB
Example02.class 2KB
UserChangePwd.class 2KB
UserChangePwd.class 2KB
AdminGoodsListServlet.class 2KB
AdminGoodsListServlet.class 2KB
TestServlet08.class 2KB
TestServlet08.class 2KB
AdminUserAddServlet.class 2KB
AdminUserAddServlet.class 2KB
Example02.class 2KB
ListCakeServlet.class 2KB
ListCakeServlet.class 2KB
GoodRecommendListServlet.class 2KB
共 1008 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
m0_72226477
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 细胞的奇迹:吃出来的免疫力(美亚畅销书!作者的TED演讲播放量超300万次!《谷物大脑》作者、《三联生活周刊》推荐!吃下对的食物,改善你的... (Z-Library).azw3
- 智能手机产品拆解,使用mindmaster打开
- 11111111111111
- 统信系统ARM64依赖openssl-1.0.2版本的libssl.so.10和libcrypto.so.10文件
- 奥比中光python sdk
- 冯超楠17.py
- OCR识别-基于视觉注意力机制Attention实现的OCR识别算法-附项目源码-优质项目实战.zip
- Java 使用蒙特卡洛方法估算PI的近似值(源代码)
- main.cpp
- 电子木鱼小程序源码电子木鱼小程序源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0