大神们,大仙们,求助!!
我在用SSH框架做分页,发现showall的页数都会改变,但每一页的内容都不改变,这是为什么呢!!!

解决方案 »

  1.   

    代码如下:
    PageBean.java:
    package com.japan.page;import java.util.ArrayList;
    import java.util.List;import com.japan.hotel.entity.Hotel;
    import com.japan.hotel.service.HotelServiceImp;
    public class PageBean { private int allrecord;//总记录数
    private int allpage;//总页数
    private int pagerecord=5;//每一页显示的记录数
    private int currentpage;//当前页面
    private HotelServiceImp hsi;
    public int getAllrecord() {
    return hsi.showall().size();
    }
    public void setAllrecord(int allrecord) {
    this.allrecord = allrecord;
    }
    public int getAllpage() {
    return this.getAllrecord()%this.getPagerecord()==0?this.getAllrecord()/this.getPagerecord():this.getAllrecord()/this.getPagerecord()+1;
    }
    public void setAllpage(int allpage) {
    this.allpage = allpage;
    }
    public int getPagerecord() {
    return pagerecord;
    }
    public void setPagerecord(int pagerecord) {
    this.pagerecord = pagerecord;
    }
    public int getCurrentpage() {
    return currentpage;
    }
    public void setCurrentpage(int currentpage) {
    this.currentpage = currentpage;
    }


    public HotelServiceImp getHsi() {
    return hsi;
    }
    public void setHsi(HotelServiceImp hsi) {
    this.hsi = hsi;
    }



    public List<Hotel>queryforpage(int currentpage){

    if(currentpage<1){
    currentpage=1;
    }
    if(currentpage>allpage){
    currentpage=allpage;
    }
    List<Hotel> list=new ArrayList<Hotel>();
    System.out.println("页面记录数为"+this.getPagerecord());
    System.out.println("currentpage为"+this.getCurrentpage()); int offset=this.getPagerecord()*(currentpage-1)+1;
    System.out.println("offset     "+offset);
    list=hsi.selectBypage(offset-1,this.getPagerecord());
    return list;

    }

    }
      

  2.   

    HotelAction:
    package com.japan.hotel.action;import java.util.List;
    import java.util.Map;import com.japan.hotel.entity.Hotel;
    import com.japan.hotel.service.HotelService;
    import com.japan.hotel.service.HotelServiceImp;
    import com.japan.page.PageBean;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;public class HotelAction extends ActionSupport{ private HotelServiceImp hsi;
    private int hid;
    private Hotel hotel;
    private String con;
    private String cons;
    private int currentpage;
    private PageBean pagebean;

    public HotelServiceImp getHsi() {
    return hsi;
    }
    public void setHsi(HotelServiceImp hsi) {
    this.hsi = hsi;
    }
    public int getHid() {
    return hid;
    }
    public void setHid(int hid) {
    this.hid = hid;
    }
    public Hotel getHotel() {
    return hotel;
    }
    public void setHotel(Hotel hotel) {
    this.hotel = hotel;
    }


    public String getCon() {
    return con;
    }
    public void setCon(String con) {
    this.con = con;
    }
    public String getCons() {
    return cons;
    }
    public void setCons(String cons) {
    this.cons = cons;
    }
    public int getCurrentpage() {
    return currentpage;
    }
    public void setCurrentpage(int currentpage) {
    this.currentpage = currentpage;
    } public PageBean getPagebean() {
    return pagebean;
    }
    public void setPagebean(PageBean pagebean) {
    this.pagebean = pagebean;
    }



    @Override
    public String execute() throws Exception {
    // TODO Auto-generated method stub
    return super.execute();
    }

    public String add() throws Exception {
    // TODO Auto-generated method stub
    boolean result=hsi.add(this.getHotel());
    if(result){
    System.out.println("action添加成功,返回list");
    return this.listall();
    }else{
    System.out.println("action添加失败,返回add");
    return "add";
    }
    }

    public String listall() throws Exception {
    // TODO Auto-generated method stub
    System.out.println("正在执行Action中listall()方法!");
    List<Hotel> list=hsi.showall();
    if(list.size()>0){
    ActionContext.getContext().getSession().put("hotellist",list);
    return "showallhotel";
    }else{
    return "add";
    }
    }

    public String delete() throws Exception {
    // TODO Auto-generated method stub
    System.out.println("正在执行Action中delete方法");
    boolean result=hsi.delete(this.getHid());
    if(result){
    System.out.println("action删除成功,返回list");
    return this.listall();
    }else{
    return "error";
    }
    }

    public String preupdate() throws Exception {
    // TODO Auto-generated method stub
    System.out.println("正在执行Action中preupdate方法");
    Hotel updatehotel=hsi.selectByHid(this.getHid());
    if(updatehotel!=null){
    System.out.println("action中需要修改的对象存在");
    //保存到session中
    ActionContext.getContext().getSession().put("prehotel",updatehotel);
        return "update";
    }else{
    System.out.println("action中需要修改的对象不存在");
    return "error";
    }
    }

    public String update() throws Exception {
    // TODO Auto-generated method stub
    System.out.println("正在执行Action中update方法");
    boolean result=hsi.update(this.getHotel());
    if(result){
    System.out.println("action修改成功!");
    return this.listall();
    }else{
    System.out.println("action修改不成功!");
    return "error";
    }
    }

    public String listBypage() throws Exception {
    // TODO Auto-generated method stub
    System.out.println("正在执行Action中分页方法");
    System.out.println(this.getCurrentpage());
    int current=this.getCurrentpage();
    if(current<1){
    current=1;
    }
    if(current>pagebean.getAllpage()){
    current=pagebean.getAllpage();
    }
    List<Hotel> list=pagebean.queryforpage(current);
    if(list.size()>0){
    System.out.println("数据库内有数据");
    Map session=ActionContext.getContext().getSession();
    session.put("pagelist",list);
    session.put("currentpage",current);
    session.put("allpage", pagebean.getAllpage());
    session.put("allrecord", pagebean.getAllrecord());
    return "showall";
    }else{
    System.out.println("数据库内没有数据");
    return "add";
    }
    }
    }
      

  3.   

    Applicationcontext:    <bean id="hdi" class="com.japan.hotel.dao.HotelDAOImp">
            <property name="sessionFactory">
            
            <ref bean="sessionFactory"></ref>
            
            </property>    
        </bean>
        
        <bean id="hsi" class="com.japan.hotel.service.HotelServiceImp">
            <property name="hdi">
            
            <ref bean="hdi"></ref>
            
            </property>    
        </bean>    <bean id="hotelaction" class="com.japan.hotel.action.HotelAction">
             <property name="hsi">
            
             <ref bean="hsi"></ref>
            
            </property>   
            
             <property name="pagebean">
            
             <ref bean="pagebean"></ref>
            
            </property>
        </bean>
         
         
        <bean id="pagebean" class="com.japan.page.PageBean">
            <property name="hsi">
            
            <ref bean="hsi"></ref>
            
            </property>    
        </bean>
      

  4.   

    画面上绑定的是bean里面的数据,你确定bean里面的数据变了吗?