Solon

weed3-solon-plugin

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

1、描述

数据扩展插件,为 Solon Data 提供基于 Weed3 的框架适配,以提供ORM支持。( Weed3 项目仓库: https://gitee.com/noear/weed3

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) -> {
            if (Solon.cfg().isDebugMode() || Solon.cfg().isFilesMode()) {
                //执行后打印sql
                WeedConfig.onExecuteAft(cmd -> {
                    System.out.println("[Weed3]" + cmd.text + "\r\n" + cmd.paramMap());
                });
            }
        });
    }
}

//配置数据源
@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

    @Db
    DbContext db;
    
    public void test(){
        //三种不同接口的样例
        App app1 = appMapper.getAppById(12);
        App app2 = appBaseMapper.getById(12);
        App app3 = db.table("app").whereEq("id",12).selectItem("*", App.class);
    }
}

具体可参考:

https://gitee.com/noear/solon_demo/tree/master/demo07.solon_weed https://gitee.com/noear/solon_demo/tree/master/demo07.solon_weed_multisource