From 36c8b7d97a69f779a53ef874e240e31af312a1dd Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Wed, 7 Sep 2022 14:30:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A70.0.3=20=E5=AE=8C?= =?UTF-8?q?=E6=88=90spring=20=E8=87=AA=E5=8A=A8=E9=85=8D=E7=BD=AE=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++-- fluent-sql-annotations/pom.xml | 2 +- fluent-sql-core/pom.xml | 2 +- fluent-sql-spring-boot-starter/pom.xml | 30 +++++++++++++++++ .../FluentSqlAutoConfiguration.java | 33 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 2 ++ fluent-sql-spring-jdbc/pom.xml | 2 +- pom.xml | 14 +++++++- 8 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 fluent-sql-spring-boot-starter/pom.xml create mode 100644 fluent-sql-spring-boot-starter/src/main/java/group/flyfish/fluent/autoconfigure/FluentSqlAutoConfiguration.java create mode 100644 fluent-sql-spring-boot-starter/src/main/resources/META-INF/spring.factories diff --git a/README.md b/README.md index 4f9be21..f6747ac 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,27 @@ ## 快速接入使用 -如果您的项目使用maven,并且使用spring-jdbc,可通过以下配置快速集成: +### SpringBoot +如果您的项目使用maven,并且使用spring-boot,可通过以下配置快速集成: +```xml + + fluent-sql-spring-boot-starter + group.flyfish.framework + 0.0.3 + +``` + +### Spring MVC +没有使用spring boot也没关系,如果项目使用spring,请只依赖它: ```xml fluent-sql-spring-jdbc group.flyfish.framework - 0.0.2 + 0.0.3 ``` -您只需要注入您的数据源即可自动完成配置。 + +然后,您只需要注入您的数据源即可自动完成配置。 ```java import javax.sql.DataSource; diff --git a/fluent-sql-annotations/pom.xml b/fluent-sql-annotations/pom.xml index 6638df3..458c002 100644 --- a/fluent-sql-annotations/pom.xml +++ b/fluent-sql-annotations/pom.xml @@ -5,7 +5,7 @@ fluent-sql group.flyfish.framework - 0.0.2 + 0.0.3 4.0.0 diff --git a/fluent-sql-core/pom.xml b/fluent-sql-core/pom.xml index f38be52..beff5f5 100644 --- a/fluent-sql-core/pom.xml +++ b/fluent-sql-core/pom.xml @@ -5,7 +5,7 @@ fluent-sql group.flyfish.framework - 0.0.2 + 0.0.3 4.0.0 diff --git a/fluent-sql-spring-boot-starter/pom.xml b/fluent-sql-spring-boot-starter/pom.xml new file mode 100644 index 0000000..1775298 --- /dev/null +++ b/fluent-sql-spring-boot-starter/pom.xml @@ -0,0 +1,30 @@ + + + + fluent-sql + group.flyfish.framework + 0.0.3 + + spring boot 快速集成组件 + 4.0.0 + + fluent-sql-spring-boot-starter + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-autoconfigure + + + group.flyfish.framework + fluent-sql-spring-jdbc + + + diff --git a/fluent-sql-spring-boot-starter/src/main/java/group/flyfish/fluent/autoconfigure/FluentSqlAutoConfiguration.java b/fluent-sql-spring-boot-starter/src/main/java/group/flyfish/fluent/autoconfigure/FluentSqlAutoConfiguration.java new file mode 100644 index 0000000..23baa0e --- /dev/null +++ b/fluent-sql-spring-boot-starter/src/main/java/group/flyfish/fluent/autoconfigure/FluentSqlAutoConfiguration.java @@ -0,0 +1,33 @@ +package group.flyfish.fluent.autoconfigure; + +import group.flyfish.fluent.operations.FluentSQLOperations; +import group.flyfish.fluent.operations.JdbcTemplateFluentSQLOperations; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; + +/** + * fluent sql自动配置 + * + * @author wangyu + */ +@AutoConfigureAfter(DataSourceAutoConfiguration.class) +public class FluentSqlAutoConfiguration { + + /** + * 动态注入初始化的bean,完成注入配置 + * + * @param dataSource 从spring datasource注入 + */ + @Bean + @ConditionalOnMissingBean(FluentSQLOperations.class) + @ConditionalOnBean(DataSource.class) + public FluentSQLOperations fluentSQLOperations(DataSource dataSource) { + return new JdbcTemplateFluentSQLOperations(new JdbcTemplate(dataSource)); + } +} diff --git a/fluent-sql-spring-boot-starter/src/main/resources/META-INF/spring.factories b/fluent-sql-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..ec791b2 --- /dev/null +++ b/fluent-sql-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + group.flyfish.fluent.autoconfigure.FluentSqlAutoConfiguration diff --git a/fluent-sql-spring-jdbc/pom.xml b/fluent-sql-spring-jdbc/pom.xml index fd0423f..4322421 100644 --- a/fluent-sql-spring-jdbc/pom.xml +++ b/fluent-sql-spring-jdbc/pom.xml @@ -5,7 +5,7 @@ fluent-sql group.flyfish.framework - 0.0.2 + 0.0.3 4.0.0 diff --git a/pom.xml b/pom.xml index b8da6ea..76f243f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ group.flyfish.framework fluent-sql pom - 0.0.2 + 0.0.3 fluent-sql A very fast sql generation engine using fluent-style api. Help you start your work without mybatis! @@ -31,6 +31,7 @@ fluent-sql-core fluent-sql-spring-jdbc fluent-sql-annotations + fluent-sql-spring-boot-starter @@ -38,6 +39,7 @@ 8 1.18.24 2.13.3 + 2.7.2 5.3.22 @@ -84,6 +86,11 @@ fluent-sql-annotations ${project.version} + + group.flyfish.framework + fluent-sql-spring-jdbc + ${project.version} + group.flyfish.framework fluent-sql-core @@ -94,6 +101,11 @@ jackson-databind ${jackson.version} + + org.springframework.boot + spring-boot-autoconfigure + ${spring-boot.version} + org.springframework spring-jdbc