!267 test:增加kotlin单独的测试模块

Merge pull request !267 from 卡莫sama/main
This commit is contained in:
Michael Yang 2023-08-10 07:46:25 +00:00 committed by Gitee
commit 48293cdb3e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
23 changed files with 471 additions and 179 deletions

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<version>1.4.8</version> <version>1.5.6</version>
</parent> </parent>
<artifactId>mybatis-flex-kotlin</artifactId> <artifactId>mybatis-flex-kotlin</artifactId>
@ -22,73 +22,33 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.5.6</version> <version>${mybatis-flex.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId> <artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version> <version>${kotlin.version}</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId> <artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version> <version>${kotlin.version}</version>
<configuration> <configuration>
<jvmTarget>1.8</jvmTarget>
<args> <args>
<arg>-Xjvm-default=all</arg> <arg>-Xjvm-default=all</arg>
</args> </args>
<jvmTarget>1.8</jvmTarget>
</configuration> </configuration>
<executions> <executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
<sourceDir>src/main/java</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<!-- 在此处指定你的注解处理器。 -->
<annotationProcessorPath>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.9</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution> <execution>
<id>compile</id> <id>compile</id>
<phase>process-sources</phase> <phase>process-sources</phase>
@ -96,6 +56,7 @@
<goal>compile</goal> <goal>compile</goal>
</goals> </goals>
</execution> </execution>
<execution> <execution>
<id>test-compile</id> <id>test-compile</id>
<phase>test-compile</phase> <phase>test-compile</phase>
@ -108,5 +69,4 @@
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.kotlintest
import com.mybatisflex.core.BaseMapper
import com.mybatisflex.core.FlexConsts
import com.mybatisflex.core.audit.AuditManager
import com.mybatisflex.core.audit.ConsoleMessageCollector
import com.mybatisflex.kotlin.entry.Entry
import com.mybatisflex.kotlin.extensions.db.*
import com.mybatisflex.kotlin.extensions.entry.*
import com.mybatisflex.kotlin.extensions.mapper.queryList
import com.mybatisflex.kotlin.extensions.sql.*
import com.mybatisflex.kotlin.scope.buildBootstrap
import com.mybatisflex.kotlintest.entry.Account
import com.mybatisflex.kotlintest.entry.table.AccountTableDef.ACCOUNT
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
import javax.sql.DataSource
import kotlin.streams.toList
fun main() {
val dataSource: DataSource = EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("schema.sql")
.addScript("data.sql")
.build()
AuditManager.setAuditEnable(true)
AuditManager.setMessageCollector(ConsoleMessageCollector())
buildBootstrap {
+ AccountMapper::class.java
dataSources {
// dataSource(FlexConsts.NAME,dataSource)
FlexConsts.NAME of dataSource
// "dataSource1" of dataSource
// "dataSource2" of dataSource
}
// + dataSource
}.start()
filter<Account> {
ACCOUNT.AGE `=` 12 or
`if`(true) { ACCOUNT.ID `in` listOf(1, 2) }
}.stream().peek(::println).peek { it.id = it.id.plus(2) }.forEach(Entry::save)
//使用表对象filter或者DB对象有两个泛型的filter方法时方法体内this为表对象无需XXX.AA调用直接AA
// ACCOUNT.filter<Account,AccountTableDef> {
// AGE `=` 12 or
// `if`(true) { ID `in` listOf(1, 2) }
// }.stream().peek(::println).peek { it.id = it.id.plus(6) }.forEach(Entry::save)
println("保存后————————")
mapper<AccountMapper>().findByAge(18,1,2).stream().peek { println(it) }.forEach(Entry::deleteById)
println("删除后————————")
ACCOUNT.all<Account>().stream().peek { println(it) }.map { it.userName = "sa"
it }.forEach(Entry::update)
println("更新后————————")
ACCOUNT.all<Account>().stream().peek { println(it) }.map {
it.id = it.id.plus(5)
it.userName = "423423"
it }.toList().batchInsert()
println("批量插入后————————")
ACCOUNT.all<Account>().stream().peek { println(it) }.toList().filter { it.id.rem(2) == 0 }.batchDeleteById()
println("批量删除后————————")
//直接使用函数查询时需指定from表
query<Account> {from(ACCOUNT)}.stream().peek { println(it) }.toList().filter { it.id.rem(3) == 0 }.map { it.userName = "哈哈"
it }.batchUpdate()
println("批量更新后————————")
//使用表对象查询时无需指定from表
ACCOUNT.query<Account> {}.forEach(::println)
}
//接口里面写方法时打这个注解才能生成Default方法否则会单独生成一个类导致报错
@JvmDefaultWithCompatibility
interface AccountMapper : BaseMapper<Account> {
fun findByAge(age: Int, vararg ids: Int): List<Account> = queryList {
select(ACCOUNT.ALL_COLUMNS)
from(ACCOUNT)
where(ACCOUNT) {
(AGE `=` age) and `if`(true) {
ID `in` ids.asList()
}
}
}
}

View File

@ -1,15 +0,0 @@
CREATE TABLE IF NOT EXISTS `tb_account`
(
`id` INTEGER PRIMARY KEY,
`u_name` VARCHAR(100) NOT NULL,
`age` INTEGER,
`birthday` DATETIME
);
CREATE TABLE IF NOT EXISTS `tb_account1`
(
`id` INTEGER PRIMARY KEY,
`u_name` VARCHAR(100) NOT NULL,
`age` INTEGER,
`birthday` DATETIME
);

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-test</artifactId>
<version>1.5.6</version>
</parent>
<artifactId>mybatis-flex-spring-kotlin-test</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.9.0</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-kotlin</artifactId>
<version>${mybatis-flex.version}</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId>
<version>${mybatis-flex.version}</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring</artifactId>
<version>${mybatis-flex.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<args>
<!--需要配置此项才能开启接口默认方法-->
<arg>-Xjvm-default=all</arg>
</args>
</configuration>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<testClasspath>${project.basedir}/src/test/kotlin</testClasspath>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<!-- 在此处指定你的注解处理器。 -->
<annotationProcessorPath>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>${mybatis-flex.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test
import com.mybatisflex.core.mybatis.FlexConfiguration
import com.mybatisflex.spring.FlexSqlSessionFactoryBean
import org.apache.ibatis.logging.stdout.StdOutImpl
import org.apache.ibatis.session.SqlSessionFactory
import org.mybatis.spring.SqlSessionFactoryBean
import org.mybatis.spring.annotation.MapperScan
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.event.ContextStartedEvent
import org.springframework.context.event.EventListener
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
import javax.sql.DataSource
@Configuration
@MapperScan("com.mybatisflex.test.mapper")
open class AppConfig {
@Bean
open fun dataSource(): DataSource? {
return EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("schema.sql")
.addScript("data-kt.sql")
.build()
}
@Bean
open fun sqlSessionFactory(dataSource: DataSource): SqlSessionFactory? {
val factoryBean: SqlSessionFactoryBean = FlexSqlSessionFactoryBean()
factoryBean.setDataSource(dataSource)
val configuration = FlexConfiguration()
configuration.logImpl = StdOutImpl::class.java
factoryBean.setConfiguration(configuration)
return factoryBean.getObject()
}
@EventListener(classes = [ContextStartedEvent::class])
open fun handleContextStartedEvent() {
println("handleContextStartedEvent listener invoked!")
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.mapper
import com.mybatisflex.core.BaseMapper
import com.mybatisflex.kotlin.extensions.mapper.queryList
import com.mybatisflex.kotlin.extensions.sql.*
import com.mybatisflex.test.model.Account
import com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT
@JvmDefaultWithCompatibility
interface AccountMapper : BaseMapper<Account> {
fun findByAge(age: Int, vararg ids: Int): List<Account> = queryList {
select(ACCOUNT.ALL_COLUMNS)
from(ACCOUNT)
where(ACCOUNT) {
(AGE `=` age) and `if`(true) {
ID `in` ids.asList()
}
}
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.kotlintest.entry package com.mybatisflex.test.model
import com.mybatisflex.annotation.Column import com.mybatisflex.annotation.Column
import com.mybatisflex.annotation.Id import com.mybatisflex.annotation.Id
@ -21,20 +21,20 @@ import com.mybatisflex.annotation.NoneListener
import com.mybatisflex.annotation.Table import com.mybatisflex.annotation.Table
import com.mybatisflex.kotlin.entry.Entry import com.mybatisflex.kotlin.entry.Entry
import java.util.* import java.util.*
/** /**
* 测试用数据类最好不要写成data class否则需要与数据库字段数据顺序一致 * 测试用数据类最好不要写成data class否则需要与数据库字段数据顺序一致
* @author 卡莫sama(yuanjiashuai) * @author 卡莫sama(yuanjiashuai)
* @date 2023/8/7 * @date 2023/8/7
*/ */
@Table(value = "tb_account", onUpdate = [NoneListener::class]) @Table(value = "tb_account", onUpdate = [NoneListener::class], onSet = [AccountOnSetListener::class])
data class Account( data class Account(
@Id var id: Int, @Id var id: Int,
@Column("u_name") var userName: String?, @Column("u_name") var userName: String?,
var age: Int?, var age: Int?,
var birthday: Date?, var birthday: Date?,
) : Entry(){ ) : Entry(){
override fun toString(): String { override fun toString(): String {
return "Account(id=$id, userName=$userName, birthday=$birthday, age=$age)" return "Account(id=$id, userName=$userName, birthday=$birthday, age=$age)"
} }
} }

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.model
import com.mybatisflex.annotation.SetListener
class AccountOnSetListener : SetListener {
override fun onSet(entity: Any, property: String, value: Any): Any {
println(">>>>>>> property: $property value:$value")
return value
}
}

View File

@ -1,4 +1,5 @@
INSERT INTO tb_account INSERT INTO tb_account
VALUES (1, 'Michael Yang', 18, '2020-01-11'); VALUES (1, 'Michael Yang', 18, '2020-01-11');
INSERT INTO tb_account INSERT INTO tb_account
VALUES (2, 'Michael Zhanng', 20, '2020-01-11'); VALUES (2, 'Michael Zhanng', 20, '2020-01-11');

View File

@ -1,4 +1,4 @@
processor.mappersGenerateEnable=false processor.mappersGenerateEnable=false
processor.tablesNameStyle=upCase processor.tablesNameStyle=lowerCase
processor.tablesDefSuffix=Def processor.tablesDefSuffix=Def
processor.allInTables=true processor.allInTables=true

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `tb_account`
(
`id` INTEGER ,
`u_name` VARCHAR(100) NOT NULL,
`age` INTEGER,
`birthday` DATETIME
);

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test
import com.mybatisflex.test.mapper.AccountMapper
import org.assertj.core.api.WithAssertions
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import kotlin.test.Test
@RunWith(SpringJUnit4ClassRunner::class)
@ContextConfiguration(classes = [AppConfig::class])
class KotlinSpringTest : WithAssertions {
@Autowired
lateinit var accountMapper: AccountMapper
@Test
fun testSelectByQuery() {
val accounts = accountMapper.findByAge(18,2)
accounts.forEach(::println)
}
}

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test
import com.mybatisflex.core.FlexConsts
import com.mybatisflex.core.audit.AuditManager
import com.mybatisflex.core.audit.ConsoleMessageCollector
import com.mybatisflex.kotlin.entry.Entry
import com.mybatisflex.kotlin.extensions.db.filter
import com.mybatisflex.kotlin.extensions.db.mapper
import com.mybatisflex.kotlin.extensions.db.query
import com.mybatisflex.kotlin.extensions.entry.*
import com.mybatisflex.kotlin.extensions.sql.*
import com.mybatisflex.kotlin.scope.buildBootstrap
import com.mybatisflex.test.mapper.AccountMapper
import com.mybatisflex.test.model.Account
import com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
import javax.sql.DataSource
import kotlin.streams.toList
import kotlin.test.Test
class KotlinTest {
@Test
fun testDb() {
val dataSource: DataSource = EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("schema.sql")
.addScript("data-kt.sql")
.build()
AuditManager.setAuditEnable(true)
AuditManager.setMessageCollector(ConsoleMessageCollector())
buildBootstrap {
+AccountMapper::class.java
dataSources {
// dataSource(FlexConsts.NAME,dataSource)
FlexConsts.NAME of dataSource
// "dataSource1" of dataSource
// "dataSource2" of dataSource
}
// + dataSource
}.start()
//
ACCOUNT.query<Account> {}.forEach(::println)
filter<Account> {
ACCOUNT.AGE `=` 12 or
`if`(true) { ACCOUNT.ID `in` listOf(1, 2) }
}.stream().peek(::println).peek { it.id = it.id.plus(2) }.forEach(Entry::save)
//使用表对象filter或者DB对象有两个泛型的filter方法时方法体内this为表对象无需XXX.AA调用直接AA
// ACCOUNT.filter<Account,AccountTableDef> {
// AGE `=` 12 or
// `if`(true) { ID `in` listOf(1, 2) }
// }.stream().peek(::println).peek { it.id = it.id.plus(6) }.forEach(Entry::save)
println("保存后————————")
mapper<AccountMapper>().findByAge(18, 1, 2).stream().peek { println(it) }.forEach(Entry::deleteById)
println("删除后————————")
ACCOUNT.all<Account>().stream().peek { println(it) }.map {
it.userName = "sa"
it
}.forEach(Entry::update)
println("更新后————————")
ACCOUNT.all<Account>().stream().peek { println(it) }.map {
it.id = it.id.plus(5)
it.userName = "423423"
it
}.toList().batchInsert()
println("批量插入后————————")
ACCOUNT.all<Account>().stream().peek { println(it) }.toList().filter { it.id.rem(2) == 0 }.batchDeleteById()
println("批量删除后————————")
//直接使用函数查询时需指定from表
query<Account> { from(ACCOUNT) }.stream().peek { println(it) }.toList().filter { it.id.rem(3) == 0 }.map {
it.userName = "哈哈"
it
}.batchUpdate()
println("批量更新后————————")
//使用表对象查询时无需指定from表
ACCOUNT.query<Account> {}.forEach(::println)
}
}

View File

@ -19,6 +19,7 @@
<module>mybatis-flex-spring-test</module> <module>mybatis-flex-spring-test</module>
<module>mybatis-flex-spring-boot-test</module> <module>mybatis-flex-spring-boot-test</module>
<module>mybatis-flex-spring-cloud-test</module> <module>mybatis-flex-spring-cloud-test</module>
<module>mybatis-flex-spring-kotlin-test</module>
</modules> </modules>
<properties> <properties>