Skip to content

Commit

Permalink
修复Kotlin使用select(predicate)方法错误.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Feb 1, 2025
1 parent 694df8b commit 11f177e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ open class KtQueryChainWrapper<T : Any>(
return typedThis
}

override fun select(predicate: Predicate<TableFieldInfo>): KtQueryChainWrapper<T> {
return select(entityClass, predicate)
}

override fun select(entityClass: Class<T>, predicate: Predicate<TableFieldInfo>): KtQueryChainWrapper<T> {
wrapperChildren.select(entityClass, predicate)
return typedThis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ open class KtQueryWrapper<T : Any> : AbstractKtWrapper<T, KtQueryWrapper<T>>, Qu
return typedThis
}

override fun select(predicate: Predicate<TableFieldInfo>): KtQueryWrapper<T> {
return select(entityClass, predicate) as KtQueryWrapper<T>
}

override fun select(entityClass: Class<T>, predicate: Predicate<TableFieldInfo>): KtQueryWrapper<T> {
this.entityClass = entityClass
this.sqlSelect.stringValue = TableInfoHelper.getTableInfo(getEntityClass()).chooseSelect(predicate)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.baomidou.mybatisplus.test.kotlin

import com.baomidou.mybatisplus.core.metadata.IPage
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers
import com.baomidou.mybatisplus.extension.toolkit.Db
Expand Down Expand Up @@ -54,6 +55,16 @@ class ChainWrappersTest : BaseDbTest<UserMapper>() {
);
}

@Test
fun testSelectByPredicate() {
Assertions.assertDoesNotThrow { ChainWrappers.ktQueryChain(User::class.java).select({ true }).list() }
doTestAutoCommit(fun(m) {
Assertions.assertDoesNotThrow {
m.selectList(KtQueryWrapper(User()).select { true })
}
})
}

override fun tableDataSql(): String {
return "insert into `sys_user`(id,username,role_id) values(1,'gozei',1),(2,'chocolate',2),(3,'sheep',1)"
}
Expand Down

0 comments on commit 11f177e

Please sign in to comment.