我用一个方法产生随机数 getMyList();
public List getContent(){
ArrayList list= this.getMyList(); //随机数
Iterator to=list.iterator();
while(to.hasNext()){
int a=Integer.parseInt(to.next().toString());
String sql = "select * from examsubject where examID="+a;
}
}
迭代随机数ArrayList list= this.getMyList();
Iterator to=list.iterator();根据每个随机数查询数据库中对应examID的内容..
问题,,,当我调用这个方法的时候假如随机数是1,23,34,53,得到数据库中的结果是hello,kitty,yes,doing,
但是在我第2次调用这个方法的时候产生的随机数又变化了,,内容也变化了,
现在我的需求是无论我如何重复调用 这个随机数产生的数字总是第一次产生的不会变,相对的内容也就不会变,这该这么实现啊。。
楼主【BlackSky_Sun】截止到2008-06-24 16:54:08的历史汇总数据(不包括此帖):
发帖数:17 发帖分:420
结贴数:14 结贴分:360
未结数:3 未结分:60
结贴率:82.35 % 结分率:85.71 %
楼主加油
if(CACHE_LIST == null){
CACHE_LIST = this.getMyList();
} ArrayList list = CACHE_LIST;
Iterator to=list.iterator();
while(to.hasNext()){
int a=Integer.parseInt(to.next().toString());
String sql = "select * from examsubject where examID="+a;
}
private List CACHE_LIST = null;public List getContent(){
if(CACHE_LIST == null){
CACHE_LIST = this.getMyList();
} ArrayList list = CACHE_LIST;
Iterator to=list.iterator();
while(to.hasNext()){
int a=Integer.parseInt(to.next().toString());
String sql = "select * from examsubject where examID="+a;
}
}
..首先我把该随机数一个一个迭代 根据随机数得到数据库中对应内容,然后放到数组中保存,该方法在一个servlet中调用,,,然后保存到session中 在a页面得到session内容显示。
int pagaNo=1; 页数,
页面首次加载,pageNo=1;
Operator tor=new Operator(); //
ArrayList lv=new ArrayList();
SubjectBean beans;
Apple app=new Apple();
List myList=new ArrayList();
myList=tor.getContent();
int pageSize=5; //初始化 行数
app.setRowCount(myList.size()); //总行数
app.setPageSize(pageSize); //每页行数
if(app.getRowCount()%app.getPageSize()==0){ //页数
app.setPageCount(app.getRowCount()/app.getPageSize());
}else{
app.setPageCount(app.getRowCount()/app.getPageSize()+1);
}
if(request.getParameter("pageNo")==null){ //传递页数值.....
app.setPageNo(1);
}else{
app.setPageNo(Integer.parseInt(request.getParameter("pageNo").toString())) ;
}
if(app.getPageNo()*app.getPageSize()<=app.getRowCount()){ //不同页的值
for(int i=(app.getPageNo()-1)*app.getPageSize();i <app.getPageNo()*app.getPageSize();i++){
beans=new SubjectBean();
beans =(SubjectBean)myList.get(i);
lv.add(beans);
}
HttpSession session3=request.getSession(); // 每页记录
session3.setAttribute("mylist", lv);根据pageNo得到不同也内容
问题是我每次根据 pageNo(页数不同)提交到servlet后它总是重新调用了那个根据随机数调用数据库的方法,每次不同,,
我现在想做的是
当页面首次加载 getContent()方法里面的内容就不会改变了无论根据页面传来什么值,它只需要关心的是在这个getContent方法返回的list中找到哪页的内容就是了。