-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the API Doc and publishing to Maven Central.
- Loading branch information
Showing
21 changed files
with
522 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Publish Packages | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml | ||
settings-path: ${{ github.workspace }} # location for the settings.xml file | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v3 | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build | ||
|
||
- name: Publish to Local and GitHub Packages | ||
run: ./gradlew publish | ||
env: | ||
SIGNING_KEY: ${{ secrets.SIGNING_KEY }} | ||
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} | ||
|
||
- name: Upload to Maven Central Portal | ||
run: ./gradlew publishToMavenCentralPortal | ||
env: | ||
MAVEN_UPLOAD_TOKEN: ${{ secrets.MAVEN_UPLOAD_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,92 @@ | ||
# flying-mybatis | ||
Let Mybatis fly, provide some basic CRUD methods by simply inheriting BaseMapper, without losing any of the original Mybatis Spring functionally. | ||
# Flying Mybatis | ||
|
||
**Read this in other languages: [English](README.md), [中文](README_zh.md).** | ||
|
||
Let Mybatis fly, provide some basic CRUD methods by simply inheriting `AutoMapper`, without losing any of the original | ||
Mybatis Spring functionally. | ||
|
||
Use steps: | ||
|
||
Add the jar package dependency, using gradle as an example: | ||
|
||
```groovy | ||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter:x.y.z' | ||
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:x.y.z' | ||
implementation 'tech.yanand:flying-mybatis:x.y.z' // Flying Mybatis jar | ||
} | ||
``` | ||
|
||
Add configuration in `application.properties` to turn on the camel case conversion, which is required: | ||
|
||
```properties | ||
mybatis.configuration.map-underscore-to-camel-case=true | ||
# XML mapper can be turned on if needed, but it is not necessary | ||
mybatis.mapper-locations=classpath:mapper/*.xml | ||
``` | ||
|
||
Add a Spring configuration class to your project: | ||
|
||
```java | ||
@Configuration | ||
@Import(AutoMapperProcessor.class) | ||
class AutoMapperConfig { | ||
} | ||
``` | ||
|
||
Create a new entity class that maps the tables and columns of the DB using `@Table` and `@Column` annotations. | ||
Take the `Book` entity as an example: | ||
|
||
```java | ||
public class Book { | ||
|
||
@Column | ||
@PrimaryKey | ||
private Long id; | ||
|
||
@Column | ||
private String name; | ||
|
||
@Column("release_date") | ||
private LocalDate publishDate; | ||
} | ||
``` | ||
|
||
Define the `BookMapper` interface, which extends from the `AutoMapper` interface. | ||
It will derive basic methods of adding, deleting, modifying, selecting, and their functionality. | ||
|
||
```java | ||
@Mapper | ||
public interface BookMapper extends AutoMapper<Book, Long> { | ||
|
||
// Custom methods that define SQL in XML Mapper. | ||
Collection<Book> selectByName(@Param("name") String name); | ||
} | ||
``` | ||
|
||
Use the `BookMapper`: | ||
|
||
```java | ||
@Autowired | ||
private BookMapper bookMapper; | ||
|
||
void testBookMapper() { | ||
int result = bookMapper.insertAll(List.of(book1, book2)); | ||
int result = bookMapper.insert(book3); | ||
|
||
Collection<Book> bookList = bookMapper.selectAll(); | ||
Book book = bookMapper.selectById(1L); | ||
Collection<Book> bookList = bookMapper.selectAllById(List.of(1L, 0L)); | ||
Collection<Book> bookList = bookMapper.selectAllByColumn("name", "test_book_2"); | ||
long count = bookMapper.countAll(); | ||
|
||
int result = bookMapper.updateAll(List.of(book3, book4)); | ||
int result = bookMapper.updateAllSelective(List.of(book3, book4)); | ||
int result = bookMapper.update(book3); | ||
int result = bookMapper.updateSelective(book3); | ||
|
||
int result = bookMapper.deleteById(1L); | ||
int result = bookMapper.deleteAllById(List.of(0L, 1L)); | ||
bookMapper.deleteAll(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 福来 Mybatis | ||
|
||
**其他语言版本: [English](README.md), [中文](README_zh.md).** | ||
|
||
让 Mybatis 飞起来,通过简单继承 AutoMapper 提供一些基本的增删改查方法,同时不失去任何原始的 Mybatis Spring 功能。 | ||
|
||
使用步骤: | ||
|
||
添加 jar 包依赖,以 gradle 为例: | ||
|
||
```groovy | ||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter:x.y.z' | ||
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:x.y.z' | ||
implementation 'tech.yanand:flying-mybatis:x.y.z' // 福来 Mybatis jar | ||
} | ||
``` | ||
|
||
在 `application.properties` 中增加配置,以开启驼峰命名转换功能,这是必须的: | ||
|
||
```properties | ||
mybatis.configuration.map-underscore-to-camel-case=true | ||
# 如果需要可以开启 XML mapper,但这不是必须的 | ||
mybatis.mapper-locations=classpath:mapper/*.xml | ||
``` | ||
|
||
在项目中增 Spring 加配置类: | ||
|
||
```java | ||
@Configuration | ||
@Import(AutoMapperProcessor.class) | ||
class AutoMapperConfig { | ||
} | ||
``` | ||
|
||
新建实体类,使用 `@Table` 和 `@Column` 注解映射数据库的表和列。以 `Book` 实体为例: | ||
|
||
```java | ||
public class Book { | ||
|
||
@Column | ||
@PrimaryKey | ||
private Long id; | ||
|
||
@Column | ||
private String name; | ||
|
||
@Column("release_date") | ||
private LocalDate publishDate; | ||
} | ||
``` | ||
|
||
定义 `BookMapper` 接口,使它继承自 `AutoMapper` 接口, 它将拥有基本的增删改查方法和功能。 | ||
|
||
```java | ||
@Mapper | ||
public interface BookMapper extends AutoMapper<Book, Long> { | ||
|
||
// 自定义方法,它可以在 XML Mapper 中定义 SQL。 | ||
Collection<Book> selectByName(@Param("name") String name); | ||
} | ||
``` | ||
|
||
使用 `BookMapper`: | ||
|
||
```java | ||
@Autowired | ||
private BookMapper bookMapper; | ||
|
||
void testBookMapper() { | ||
int result = bookMapper.insertAll(List.of(book1, book2)); | ||
int result = bookMapper.insert(book3); | ||
|
||
Collection<Book> bookList = bookMapper.selectAll(); | ||
Book book = bookMapper.selectById(1L); | ||
Collection<Book> bookList = bookMapper.selectAllById(List.of(1L, 0L)); | ||
Collection<Book> bookList = bookMapper.selectAllByColumn("name", "test_book_2"); | ||
long count = bookMapper.countAll(); | ||
|
||
int result = bookMapper.updateAll(List.of(book3, book4)); | ||
int result = bookMapper.updateAllSelective(List.of(book3, book4)); | ||
int result = bookMapper.update(book3); | ||
int result = bookMapper.updateSelective(book3); | ||
|
||
int result = bookMapper.deleteById(1L); | ||
int result = bookMapper.deleteAllById(List.of(0L, 1L)); | ||
bookMapper.deleteAll(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
plugins { | ||
id 'java' | ||
id 'java-library' | ||
id 'maven-publish' | ||
id 'signing' | ||
id 'tech.yanand.gradle.maven-central-publish' version '0.1.0-beta.4' | ||
} | ||
|
||
group = 'tech.qianmi.flyingmybatis' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
sourceCompatibility = '21' | ||
} | ||
group = 'tech.yanand' | ||
version = '0.1.0-beta' | ||
|
||
repositories { | ||
mavenCentral() | ||
|
@@ -16,14 +15,92 @@ repositories { | |
dependencies { | ||
implementation 'org.mybatis:mybatis:3.5.16' | ||
implementation 'org.mybatis:mybatis-spring:3.0.3' | ||
implementation 'org.springframework:spring-tx:6.1.6' | ||
implementation 'org.slf4j:slf4j-api:2.0.12' | ||
implementation 'org.springframework:spring-tx:6.1.8' | ||
implementation 'org.slf4j:slf4j-api:2.0.13' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.2.5' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.2.6' | ||
testRuntimeOnly 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3' | ||
testRuntimeOnly 'org.hsqldb:hsqldb:2.7.2' | ||
testRuntimeOnly 'org.hsqldb:hsqldb:2.7.3' | ||
} | ||
|
||
java { | ||
sourceCompatibility = '17' | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
from components.java | ||
|
||
versionMapping { | ||
usage('java-api') { | ||
fromResolutionOf('runtimeClasspath') | ||
} | ||
usage('java-runtime') { | ||
fromResolutionResult() | ||
} | ||
} | ||
|
||
pom { | ||
name = 'Flying Mybatis' | ||
description = 'Let Mybatis fly, provide some basic CRUD methods by simply inheriting `AutoMapper`, ' + | ||
'without losing any of the original Mybatis Spring functionally.' | ||
url = 'https://github.com/yananhub/flying-mybatis' | ||
|
||
licenses { | ||
license { | ||
name = 'The Apache License, Version 2.0' | ||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | ||
} | ||
} | ||
developers { | ||
developer { | ||
id = 'yananhub' | ||
name = 'Richard Zhang' | ||
email = '[email protected]' | ||
} | ||
} | ||
scm { | ||
connection = 'scm:git:https://github.com/yananhub/flying-mybatis.git' | ||
developerConnection = 'scm:git:https://github.com/yananhub/flying-mybatis.git' | ||
url = 'https://github.com/yananhub/flying-mybatis' | ||
} | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
name = "Local" | ||
url = layout.buildDirectory.dir('repos/bundles') | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
if (System.getenv('SIGNING_KEY')) { | ||
def signingKey = System.getenv('SIGNING_KEY').replace('\\n', '\n') | ||
def signingPassword = System.getenv('SIGNING_PASSWORD') | ||
useInMemoryPgpKeys(signingKey, signingPassword) | ||
|
||
sign publishing.publications.mavenJava | ||
} | ||
} | ||
|
||
javadoc { | ||
source = fileTree('src/main/java') { | ||
exclude 'tech/yanand/flyingmybatis/AutoMapperProvider.java' | ||
} | ||
options.addBooleanOption('html5', true) | ||
} | ||
|
||
mavenCentral { | ||
repoDir = layout.buildDirectory.dir('repos/bundles') | ||
authToken = System.getenv('MAVEN_UPLOAD_TOKEN') | ||
} |
Oops, something went wrong.