Solon

activerecord-solon-plugin

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

1、描述

数据扩展插件,为 Solon Data 提供基于 activerecord 的框架适配,以提供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(ActiveRecordPlugin.class, arp -> {
                //启用开发或调试模式(可以打印sql)
                if (Solon.cfg().isDebugMode() || Solon.cfg().isFilesMode()) {
                    arp.setDevMode(true);
                }
            });
        });
    }
}

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

//应用
@Service
public class AppService{
    public void test(){
       App app = Db.template("appx_get", app_id).findFirst();
    }
}

具体可参考:

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