日期:2014-05-17  浏览次数:20687 次

求高手帮忙看看下面这个代码!!!!
这是GoodsBean代码
package com.shop.model;

public class GoodBean {


private long goodsId;
private String goodsName;
private String goodsIntro;
private float goodsPrice;
private int goodsNum;
private String publisher;
private String photo;
private String type;
public long getGoodsId() {
return goodsId;
}
public void setGoodsId(long goodsId) {
this.goodsId = goodsId;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getGoodsIntro() {
return goodsIntro;
}
public void setGoodsIntro(String goodsIntro) {
this.goodsIntro = goodsIntro;
}
public float getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(float goodsPrice) {
this.goodsPrice = goodsPrice;
}
public int getGoodsNum() {
return goodsNum;
}
public void setGoodsNum(int goodsNum) {
this.goodsNum = goodsNum;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

}


这是显示分页代码


//这是对数据库中的表进行操作
package com.shop.model;

import java.sql.*;
import java.util.ArrayList;

public class GoodsBeanBO {

private Connection con=null;
private PreparedStatement ps=null;
private ResultSet rs=null;


//分页显示
public ArrayList getGoodsByPage(int pageSize,int pageNow){
ArrayList al=new ArrayList();
try {

con=new DBConnection().getConnection();
ps=con.prepareStatement("select top "+pageSize+" * from goods where goodsId not in(select top "+pageSize*(pageNow-1)+" goodsId from goods);");
rs=ps.executeQuery();

while(rs.next()){
GoodBean gb=new GoodBean();
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(al);
}

} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
this.close();

}
return al;

}

//关闭资源
public void close(){
try {
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();

}
if(con!=null){
con.close();
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
}


这是jsp代码:
<%@ page language="java" import="java.util.*,com.shop.model.*"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//接受al集合
ArrayList<GoodBean> al=new GoodsBeanBO().getGoodsByPage(6,1);
for(int i=0;i<al.size();i++){
 GoodBean gb=(GoodBean)al.get(i);
 System.out.println("商品的编号是:"+gb.getGoodsId());
}

%>

GoodBean gb