Solon

beetlsql-solon-plugin

<dependency>
    <groupId>org.noear</groupId>
    <artifactId>beetlsql-solon-plugin</artifactId>
</dependency>

1、描述

数据扩展插件,为 Solon Data 提供基于 beetlsql 的框架适配,以提供ORM支持。

2、配置示例

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

3、应用示例

//启动应用
public class DemoApp {
    public static void main(String[] args) {
        Solon.start(DemoApp.class, args, app -> {
            //订阅事件,后以定制
            app.onEvent(SQLManagerBuilder.class, c -> {
                //启用开发或调试模式(可以打印sql)
                if (Solon.cfg().isDebugMode() || Solon.cfg().isFilesMode()) {
                    c.addInterDebug();
                }
            });
        });
    }
}

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

//应用
@Service
public class AppService{
    @Db
    AppMapper appMapper; //xml sql mapper

    @Db
    BaseMapper<App> appBaseMapper; //base mapper
    
    public void test(){
        //三种不同接口的样例
        App app1 = appMapper.getAppById(12);
        App app2 = appBaseMapper.getById(12);
    }
}

具体可参考:

https://gitee.com/noear/solon_demo/tree/master/demo09.solon_beetlsql