Solon

mybatis-sqlhelper-solon-plugin

v2.7.3 </> markdown
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>mybatis-sqlhelper-solon-plugin</artifactId>
</dependency>

1、描述

数据扩展插件,为 mybatis-solon-plguin 插件提供分页支持。

2、配置示例

solon.app:
    name: demoapp
    group: demo

demo.db1:
    schema: rock
    jdbcUrl: jdbc:mysql://localhost:3306/rock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true
    driverClassName: com.mysql.cj.jdbc.Driver
    username: root
    password: 123456

#映射配置
mybatis.db1:
    typeAliases:    #支持包名 或 类名(.class 结尾)
        - "demo.model"
    mappers:        #支持包名 或 类名(.class 结尾)或 xml(.xml结尾)
        - "demo.dso.mapper"


#分页组件的配置
sqlhelper:
    mybatis:
        instrumentor:
            dialect: "mysql"
            cache-instrumented-sql: true
            subquery-paging-start-flag: "[PAGING_StART]"
            subquery-paging-end-flag: "[PAGING_END]"
        pagination:
            count: true
            default-page-size: 10
            use-last-page-if-page-no-out: true
            count-suffix: _COUNT

3、应用示例

//配置数据源
@Configuration
public class Config {
    @Bean
    public DataSource db1(@Inject("${demo.db1}") HikariDataSource ds) {
        return ds;
    }
}

//应用
@Component
public class AppService{
    @Db
    AppMapper appMapper; 
    
    public Object test(){
        //分页查询
        SqlPaginations.preparePagination(2,2);
        return appxMapper.appx_get_page();
    }
    
    public PagingResult test2(){
        //分页查询,带总数
        PagingRequest request = SqlPaginations.preparePagination(2,2);
        appxMapper.appx_get_page();
        
        return request.getResult();
    }
}

具体可参考:

https://gitee.com/noear/solon-examples/tree/main/4.Solon-Data/demo4024-mybatis_sqlhelper

https://github.com/fangjinuo/sqlhelper/blob/master/.wiki/readme_cn.md