ebean

官方网址:https://ebean.io/

创建maven项目

pom.xml


    UTF-8
    1.8




    
        mysql
        mysql-connector-java
        8.0.16
        test
    
    
    
        io.ebean
        ebean
        11.41.1
    

    
    
        io.ebean
        ebean-querybean
        11.41.1
    

    
    
        io.ebean
        querybean-generator
        11.41.1
        provided
    


    
    
    
        io.ebean.test
        ebean-test-config
        11.41.1
        test
    

    
        org.slf4j
        slf4j-api
        1.7.25
    

    
        ch.qos.logback
        logback-classic
        1.2.3
    

    
        org.testng
        testng
        6.8.7
        test
    



    

        
            org.apache.maven.plugins
            maven-compiler-plugin
            3.7.0
            
                ${java.version}
                ${java.version}
                true
                true
            
        

        
            io.repaint.maven
            tiles-maven-plugin
            2.12
            true
            
                
                    org.avaje.tile:java-compile:1.1
                    io.ebean.tile:enhancement:11.41.1
                
            
        

        
            org.apache.maven.plugins
            maven-surefire-plugin
            2.19.1
            
            
            
            
            
            
            
                
                    default-test
                    test
                    
                        test
                    
                
            
        

    

ebean.mf 文件配置

entity-packages: org.example.domain
transactional-packages: org.example
querybean-packages: none

profile-location: true
entity-packages: org.example.domain
transactional-packages: org.example
querybean-packages: org.example

https://ebean.io/docs/introduction/manifest

然后在写一个application.yml文件 增加数据库配置信息

datasource:
  db:
    username: test
    password: test
    url: jdbc:mysql://127.0.0.1:3306/test
    driver: com.mysql.cj.jdbc.Driver

接下来就是编写一个bean类继承Model

编写一个finder 继承自Finder

旧EbeanServer 和新DataBase,获取方法参考:https://ebean.io/docs/introduction/

public static EbeanServer getEbeanServer(){
    EbeanServer server = null;
    ServerConfig config = new ServerConfig();
    config.setName("test");
    config.loadFromProperties();
    config.setDefaultServer(true);
    config.setDdlRun(true);
    config.setDdlCreateOnly(true);
    try {
        server = EbeanServerFactory.create(config);
    } catch (Exception e) {
        config.setDdlRun(false);
        server = EbeanServerFactory.create(config);
    }
    return server;
}

public static Database getDataBase(){
    // configuration ...
    DatabaseConfig config = new DatabaseConfig();
    config.setName("test");
    config.loadFromProperties();
    config.addPackage("mode包名");

    // create database instance
    return DatabaseFactory.create(config);
}

 

你可能感兴趣的:(ebean)