Solon v3.0.3

mybatis-sqlhelper-solon-plugin

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

1、描述

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

2、配置示例

#数据源配置块(名字按业务需要取,与 @Db 那边对起来就好)
solon.dataSources:
  db1!:
    class: "com.zaxxer.hikari.HikariDataSource"
    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、应用示例

//应用
@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