自定义分页

 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.labPage.Text = "1";
            this.contrlRepeater();
        }
    }
    //分页
    public void contrlRepeater()
    {
        Maticsoft.BLL.News newsBll = new Maticsoft.BLL.News();
        DataSet Ds = new DataSet();
        Ds = newsBll.GetList(15, "", "news_AddTime desc");//返回前15条记录

        //分页

        PagedDataSource pds = new PagedDataSource();

        pds.DataSource = Ds.Tables["ds"].DefaultView;

        pds.AllowPaging = true;

        pds.PageSize = 6;

        pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
        ren.DataSource = pds;

        LabCountPage.Text = pds.PageCount.ToString();

        labPage.Text = (pds.CurrentPageIndex + 1).ToString();

        this.lbtnpritPage.Enabled = true;

        this.lbtnFirstPage.Enabled = true;

        this.lbtnNextPage.Enabled = true;

        this.lbtnDownPage.Enabled = true;

        if (pds.CurrentPageIndex < 1)
        {
            this.lbtnpritPage.Enabled = false;
            this.lbtnFirstPage.Enabled = false;
        }
        if (pds.CurrentPageIndex == pds.PageCount - 1)
        {
            this.lbtnNextPage.Enabled = false;
            this.lbtnDownPage.Enabled = false;
        }
        ren.DataBind();
    }
    //首页
    protected void lbtnFirstPage_Click(object sender, EventArgs e)
    {
        this.labPage.Text = "1";
        this.contrlRepeater();
    }
    //上一页
    protected void lbtnpritPage_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
        this.contrlRepeater();
    }
    //下一页
    protected void lbtnNextPage_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
        this.contrlRepeater();
    }
    //尾页
    protected void lbtnDownPage_Click(object sender, EventArgs e)
    {
        this.labPage.Text = this.LabCountPage.Text;
        this.contrlRepeater();
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis Plus提供了丰富的分页功能,但如果需要自定义分页逻辑,你可以按照以下步骤进行操作: 1. 创建一个自定义的分页类,该类需要继承`com.baomidou.mybatisplus.extension.plugins.pagination.Page`,并重写其中的方法,以实现自定义的分页逻辑。例如,可以根据特定条件进行数据筛选或排序。 ```java import com.baomidou.mybatisplus.extension.plugins.pagination.Page; public class CustomPage<T> extends Page<T> { // 重写构造方法或其他方法 @Override public List<T> getRecords() { // 自定义获取数据的逻辑 // 在这里可以根据条件进行数据筛选或排序 // 返回自定义的数据列表 } // 其他自定义方法 } ``` 2. 在Mapper接口中定义一个方法,用于执行自定义分页查询。该方法需要接受自定义分页类作为参数,并返回自定义分页类的对象。 ```java import com.baomidou.mybatisplus.core.mapper.BaseMapper; public interface YourMapper extends BaseMapper<YourEntity> { CustomPage<YourEntity> customSelectPage(CustomPage<YourEntity> page); // 其他方法 } ``` 3. 在对应的Mapper XML文件中编写SQL语句,实现自定义的分页查询逻辑。可以使用MyBatis的动态SQL语句来根据传入的参数进行不同的处理。 ```xml <select id="customSelectPage" parameterType="com.yourpackage.CustomPage" resultMap="YourResultMap"> SELECT * FROM your_table WHERE ... ORDER BY ... LIMIT #{offset}, #{size} </select> ``` 4. 在Service层中调用自定义的分页查询方法,并传入自定义分页类对象作为参数。 ```java import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class YourServiceImpl extends ServiceImpl<YourMapper, YourEntity> implements YourService { @Override public CustomPage<YourEntity> customSelectPage(CustomPage<YourEntity> page) { return baseMapper.customSelectPage(page); } // 其他方法 } ``` 5. 最后,在Controller层中调用Service层的自定义分页查询方法,并将结果返回给前端。 ```java @RestController @RequestMapping("/your") public class YourController { @Autowired private YourService yourService; @GetMapping("/customPage") public CustomPage<YourEntity> customPage(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) { CustomPage<YourEntity> page = new CustomPage<>(pageNum, pageSize); return yourService.customSelectPage(page); } // 其他接口 } ``` 以上是使用MyBatis Plus实现自定义分页的简单示例,你可以根据实际需求进行相应的修改和扩展。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值