Java-ORM数据库框架CDM介绍

2018-12-27  本文已影响0人  懒得出风头

一个使用简单,零配置,容错率高,效率的Java™ ORM 数据库框架

github链接

✨ 特性

Bootstrap bootstrap = BootStrapFactoty.load("default",config->{
    config.setDriver(Driven.SQLITE);
    config.setUrl("jdbc:sqlite:test.sqlite");
});
        
class User implements BasicBean{
            
    int id;
    String name;

    @Override
    public String primarykey() {
        return "id";
    }
}
        
bootstrap.query(new User()).create();

支持常用数据库 Mysql,Sqlite,Oracle,Sqlserver

与Mybatis比较

与Hibernate比较

文档

Please refer to the Wiki for continuous updates

示例

1.pom文件中导入依赖,<a href="https://mvnrepository.com/artifact/online.sanen/cdm-core">Maven address</a>

<!-- https://mvnrepository.com/artifact/online.sanen/cdm-core -->
<dependency>
    <groupId>online.sanen</groupId>
    <artifactId>cdm-core</artifactId>
    <!-- Try to keep it up to date -->
    <version>2.0.5</version>
</dependency>

2.创建实体类

实体类实现 BasicBean 接口即可.

class User implements BasicBean{
    int id;
         
    String name;

    @Override
    public String primarykey() {
        return "id";
    }
         
}

3.创建 BootStrap 实例

Bootstrap bootstrap = BootStrapFactoty.load( obstract -> {
    obstract.setDriver(Driven.MYSQL);
    obstract.setUrl("jdbc:mysql://127.0.0.1:3306/test?useSSL=false");
    obstract.setUsername("root");
    obstract.setPassword("root");
    obstract.setFormat(true);
});

4.CRUD 操作

Add

bootstrap.query(user).insert();

Delete

bootstrap.query(user).delete();

Update

bootstrap.query(user).update();

Find by pk

bootstrap.query(User.class,2).find();

List query

bootstrap.query(User.class).addEntity(User.class).list();

Add Condition

bootstrap.query(User.class)
    .addEntity(User.class)
    .addContion(C.eq("name","tom"))
    .list();
上一篇 下一篇

猜你喜欢

热点阅读