JavaWeb基础+oracle实现简单简单分页商品浏览与加入购物车系统

1.首先建立项目,大概目录如下图

绪论:也是一个小作业,测试过没有什么bug,数据库用的tomcat连接池,我也是初学者,分享出来对java的初学者或许会有小帮助,



1.1商品的po层里面就是和数据库表字段对应的数据的get和set方法和构造方法。


2.首先是商品浏览模块的IGoodsDao接口
package cn.hpe.dao;

import java.util.List;

import cn.hpe.po.GoodsInfo;

public interface IGoodsDao {

/**
* 分页显示商品信息的栏目 pageSize=3;
*
* @return
*/
public List<GoodsInfo> getGoodsList(int currentPages, int pageSizes)
throws Exception;

/**
* 获取总页数
*/
public int getAllPage() throws Exception;

/**
* 查询所有商品的信息; return list;
*/
public List<GoodsInfo> getAllGoodsList(String id) throws Exception;

}

2.1是商品浏览界面的实现部分


package cn.hpe.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.hpe.dao.BaseDao;
import cn.hpe.dao.IGoodsDao;
import cn.hpe.po.GoodsInfo;

public class GoodsDaoImpl implements IGoodsDao {

/**
* 分页显示商品信息的栏目 pageSize=3;
*
* @return
*/
@Override
public List<GoodsInfo> getGoodsList(int currentPages, int pageSizes)
throws Exception {
List<GoodsInfo> list = new ArrayList<GoodsInfo>();
try {
int currentPage = currentPages;
int pageSize = pageSizes;
int xy = currentPage * pageSize;
int dy = (currentPage - 1) * pageSize;
Connection conn = BaseDao.getConn();
String sql = "select * from (select t.*,rownum r from TB_GOODS t where rownum<="
+ xy + ")where r>" + dy + "";

PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
GoodsInfo gi = new GoodsInfo();
gi.setId(rs.getString("ID"));
gi.setName(rs.getString("NAME"));
gi.setPrice(rs.getDouble("PRICE"));
gi.setCompany(rs.getString("COMPANY"));
gi.setLeaveDate(rs.getString("LEAVE_DATE"));
gi.setDescription(rs.getString("DESCRIPTION"));
list.add(gi);
}
rs.close();
ps.close();
conn.close();

} catch (Exception ex) {
ex.printStackTrace();
throw new Exception();
}

return list;
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值