From 4a016cc8931fafbd0464143e695e850f2a969a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Sat, 22 Apr 2023 11:27:05 +0800 Subject: [PATCH] add banner print --- .../com/mybatisflex/core/FlexGlobalConfig.java | 12 ++++++++++++ .../core/mybatis/FlexConfiguration.java | 1 + .../mybatis/FlexSqlSessionFactoryBuilder.java | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java index fb887d0c..3a14b96e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java @@ -31,6 +31,11 @@ import java.util.concurrent.ConcurrentHashMap; */ public class FlexGlobalConfig { + /** + * 启动是否打印 banner 和 版本好 + */ + private boolean printBanner = true; + /** * 默认使用 Mysql 数据库类型 */ @@ -66,6 +71,13 @@ public class FlexGlobalConfig { private Object normalValueOfLogicDelete = FlexConsts.LOGIC_DELETE_NORMAL; private Object deletedValueOfLogicDelete = FlexConsts.LOGIC_DELETE_DELETED; + public boolean isPrintBanner() { + return printBanner; + } + + public void setPrintBanner(boolean printBanner) { + this.printBanner = printBanner; + } public DbType getDbType() { return dbType; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java index cd0206ce..822b1e3d 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java @@ -62,6 +62,7 @@ public class FlexConfiguration extends Configuration { initDefaultMappers(); } + /** * 设置 mybatis-flex 默认的 Mapper * 当前只有 RowMapper {@link RowMapper} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java index 5ab49f63..b5c23e97 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexSqlSessionFactoryBuilder.java @@ -15,6 +15,7 @@ */ package com.mybatisflex.core.mybatis; +import com.mybatisflex.core.FlexConsts; import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.dialect.DbType; import com.mybatisflex.core.dialect.DbTypeUtil; @@ -63,10 +64,25 @@ public class FlexSqlSessionFactoryBuilder extends SqlSessionFactoryBuilder { //设置全局配置的 sessionFactory 和 dbType initGlobalConfig(configuration, sessionFactory, dbType); + printBanner(); + return sessionFactory; } + private void printBanner() { + if (!FlexGlobalConfig.getDefaultConfig().isPrintBanner()) { + return; + } + String banner = " __ __ _ _ _ _____ _ \n" + + " | \\/ |_ _| |__ __ _| |_(_)___ | ___| | _____ __\n" + + " | |\\/| | | | | '_ \\ / _` | __| / __| | |_ | |/ _ \\ \\/ /\n" + + " | | | | |_| | |_) | (_| | |_| \\__ \\ | _| | | __/> < \n" + + " |_| |_|\\__, |_.__/ \\__,_|\\__|_|___/ |_| |_|\\___/_/\\_\\\n" + + " |___/ v" + FlexConsts.VERSION + " https://mybatis-flex.com"; + System.out.println(banner); + } + /** * 设置全局配置 * @@ -84,5 +100,4 @@ public class FlexSqlSessionFactoryBuilder extends SqlSessionFactoryBuilder { } - }