📄 goodsbeanbo.java
字号:
package com.my.model;
import java.sql.*;
import java.util.ArrayList;
public class GoodsBeanBO
{
private ResultSet rs=null;
private Connection ct=null;
private PreparedStatement ps=null;
private int rowCount = 0;
private int pageCount = 0;
public ArrayList getClassifyMovie(int pageSize,int pageNow)
{
ArrayList<GoodsBean> al=new ArrayList<GoodsBean>();
try {
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select * from goods where goodsId in(select goodsId from goods where type='香港电影')limit "+(pageNow-1)*pageSize+","+pageSize+"");
rs=ps.executeQuery();
while(rs.next())
{
GoodsBean gb=new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setPublisher(rs.getString(6));
gb.setPhoto(rs.getString(7));
gb.setType(rs.getString(8));
al.add(gb);
}
} catch(Exception e) {
e.printStackTrace();
}finally
{
this.close();
}
return al;
}
public ArrayList getClassifyMovie1(int pageSize,int pageNow)
{
ArrayList<GoodsBean> al=new ArrayList<GoodsBean>();
try {
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select * from goods where goodsId in(select goodsId from goods where type='大陆电影')limit "+(pageNow-1)*pageSize+","+pageSize+"");
rs=ps.executeQuery();
while(rs.next())
{
GoodsBean gb=new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setPublisher(rs.getString(6));
gb.setPhoto(rs.getString(7));
gb.setType(rs.getString(8));
al.add(gb);
}
} catch (Exception e) {
e.printStackTrace();
}finally
{
this.close();
}
return al;
}
public ArrayList getGoodsByPage(int pageSize,int pageNow)
{
ArrayList<GoodsBean> al=new ArrayList<GoodsBean>();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select * from goods limit "+(pageNow-1)*pageSize+","+pageSize+"");
rs=ps.executeQuery();
while(rs.next())
{
GoodsBean gb=new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setPublisher(rs.getString(6));
gb.setPhoto(rs.getString(7));
gb.setType(rs.getString(8));
al.add(gb);
}
}
catch(Exception e)
{
e.printStackTrace();
}finally
{
this.close();
}
return al;
}
public boolean checkCount(String goodsId)
{ GoodsBean gb=new GoodsBean();
gb=this.getGoodsBean(goodsId);
boolean b=false;
int c=gb.getSkimTimes()+1;
//System.out.println(gb.getSkimTimes());
//System.out.println(c);
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("update goods set skimTimes='"+c+"'where goodsId ="+goodsId+"" );
int a=ps.executeUpdate();
if(a==1)
{
b=true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
return b;
}
public ArrayList getGoodsCharts()
{
ArrayList<GoodsBean> al=new ArrayList<GoodsBean>();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select * from goods order by skimTimes desc ");
rs=ps.executeQuery();
while(rs.next())
{
GoodsBean gb=new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setPublisher(rs.getString(6));
gb.setPhoto(rs.getString(7));
gb.setType(rs.getString(8));
gb.setSkimTimes(rs.getInt(9));
al.add(gb);
}
}
catch(Exception e)
{
e.printStackTrace();
}finally
{
this.close();
}
return al;
}
public GoodsBean getGoodsBean(String id)
{
GoodsBean gb=new GoodsBean();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select * from goods where goodsId='"+id+"'");
rs=ps.executeQuery();
//ps.setString(1,id);
if(rs.next())
{
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setPublisher(rs.getString(6));
gb.setPhoto(rs.getString(7));
gb.setType(rs.getString(8));
gb.setSkimTimes(rs.getInt(9));
//System.out.println(gb.getSkimTimes());
}
}
catch(Exception e)
{
e.printStackTrace();
}finally
{
this.close();
}
return gb;
}
public int getClassifyPageCount(int pageSize)
{
try {
ct = new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from goods where goodsId in(select goodsId from goods where type='香港电影')");
rs=ps.executeQuery();
if (rs.next()) {
rowCount = rs.getInt(1);
//System.out.println(rowCount);
}
if (rowCount % pageSize == 0) {
pageCount = rowCount / pageSize;
} else {
pageCount = rowCount / pageSize + 1;
}
} catch (Exception e) {
e.printStackTrace();
}
return pageCount;
}
public int getClassifyPageCount1(int pageSize)
{
try {
ct = new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from goods where goodsId in(select goodsId from goods where type='大陆电影')");
rs=ps.executeQuery();
if (rs.next()) {
rowCount = rs.getInt(1);
//System.out.println(rowCount);
}
if (rowCount % pageSize == 0) {
pageCount = rowCount / pageSize;
} else {
pageCount = rowCount / pageSize + 1;
}
} catch (Exception e) {
e.printStackTrace();
}
return pageCount;
}
public int getPageCount(int pageSize) {
try {
ct = new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from goods");
rs=ps.executeQuery();
if (rs.next()) {
rowCount = rs.getInt(1);
}
if (rowCount % pageSize == 0) {
pageCount = rowCount / pageSize;
} else {
pageCount = rowCount / pageSize + 1;
}
} catch (Exception e) {
e.printStackTrace();
}
return pageCount;
}
public void close() {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (ps != null) {
ps.close();
ps = null;
}
if (ct != null) {
ct.close();
ct = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -