View Javadoc
1   /*
2    *    Copyright 2016-2025 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package examples.paging;
17  
18  import static examples.animal.data.AnimalDataDynamicSqlSupport.*;
19  
20  import java.util.List;
21  
22  import org.apache.ibatis.annotations.Arg;
23  import org.apache.ibatis.annotations.SelectProvider;
24  import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
25  import org.mybatis.dynamic.sql.select.SelectDSL;
26  import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
27  import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
28  
29  import examples.animal.data.AnimalData;
30  
31  public interface LimitAndOffsetMapper {
32  
33      @SelectProvider(type=SqlProviderAdapter.class, method="select")
34      @Arg(column = "id", javaType = int.class, id = true)
35      @Arg(column = "animal_name", javaType = String.class)
36      @Arg(column = "brain_weight", javaType = double.class)
37      @Arg(column = "body_weight", javaType = double.class)
38      List<AnimalData> selectMany(SelectStatementProvider selectStatement);
39  
40      default QueryExpressionDSL<LimitAndOffsetAdapter<List<AnimalData>>> selectWithLimitAndOffset(int limit, int offset) {
41          return SelectDSL.select(selectModel -> LimitAndOffsetAdapter.of(selectModel, this::selectMany, limit, offset),
42                  id, animalName, brainWeight, bodyWeight)
43                  .from(animalData);
44      }
45  }