如何配置数据源分页

// 设置数据源参数
 protected void RepeaterDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
 {

  // 获取分页参数
  int maximumRows = PagerNavigation1.PageSize;
  int startRowIndex = 0;

  if (null != ViewState["maximumRows"])
   int.TryParse(ViewState["maximumRows"].ToString(), out maximumRows);
  if (null != ViewState["startRowIndex"])
   int.TryParse(ViewState["startRowIndex"].ToString(), out startRowIndex);


  e.Arguments.MaximumRows = maximumRows;
  e.Arguments.StartRowIndex = startRowIndex;
  //e.InputParameters["maximumRows"] = maximumRows;
  //e.InputParameters["startRowIndex"] = startRowIndex;

  
 }

 

通过e.Arguments设置最大行,和开始行索引

 

 

-------------------------==============================

// 保存分页参数
  ViewState["maximumRows"] = PagerNavigation1.PageSize;
  ViewState["startRowIndex"] = PagerNavigation1.PageSize * (e.NewPageIndex);

 

 

 

----------------------------------页面-------------------------------

<asp:ObjectDataSource ID="RepeaterDataSource" runat="server" SelectMethod="GetBooksByCategory"
  TypeName="Bll.Book" EnablePaging="True" OnSelecting="RepeaterDataSource_Selecting">
  <SelectParameters>
   <asp:QueryStringParameter Name="cid" QueryStringField="cid" Type="Int32" />
   <asp:QueryStringParameter Name="sortField" QueryStringField="sort" Type="String" />
   <asp:Parameter Name="maximumRows" Type="Int32" />
   <asp:Parameter Name="startRowIndex" Type="Int32" />
  </SelectParameters>
 </asp:ObjectDataSource>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
可能是因为在配置数据源时没有正确指定数据源的名称,导致分页插件无法识别默认的数据源。需要在配置文件中明确指定数据源的名称,例如: ``` mybatis-plus: configuration: map-underscore-to-camel-case: true default-fetch-size: 100 default-statement-timeout: 30 global-config: db-config: id-type: auto logic-delete-value: 1 logic-not-delete-value: 0 field-strategy: not_empty db-type: mysql banner: false mapper-locations: classpath:/mapper/**Mapper.xml type-aliases-package: com.example.demo.entity # 指定数据源名称 datasource: druid: master: url: jdbc:mysql://localhost:3306/db1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver slave: url: jdbc:mysql://localhost:3306/db2?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver ``` 然后在分页插件中指定数据源名称: ``` @Configuration public class MybatisPlusConfig { @Autowired private DruidDataSource masterDataSource; @Autowired private DruidDataSource slaveDataSource; /** * 分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); // 指定数据源名称 paginationInterceptor.setSqlParser(new TenantSqlParser().setTenantHandler(new MyTenantHandler()).setDataSource("master")); return paginationInterceptor; } /** * 多数据源配置 */ @Bean @Primary public DynamicDataSource dynamicDataSource() { Map<Object, Object> targetDataSources = new HashMap<>(); targetDataSources.put("master", masterDataSource); targetDataSources.put("slave", slaveDataSource); DynamicDataSource dynamicDataSource = new DynamicDataSource(); dynamicDataSource.setTargetDataSources(targetDataSources); dynamicDataSource.setDefaultTargetDataSource(masterDataSource); return dynamicDataSource; } } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值