mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
fixed 1.2.4新增的 paginateAs 异常 close #I73BP6
This commit is contained in:
parent
75329948dd
commit
0cffd08ce7
@ -16,6 +16,7 @@
|
||||
package com.mybatisflex.core;
|
||||
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.mybatis.MappedStatementTypes;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.provider.EntitySqlProvider;
|
||||
import com.mybatisflex.core.query.CPI;
|
||||
@ -615,7 +616,7 @@ public interface BaseMapper<T> {
|
||||
|
||||
//清除group by 去查询数据
|
||||
CPI.setGroupByColumns(queryWrapper, null);
|
||||
CPI.setSelectColumns(queryWrapper, Arrays.asList(count()));
|
||||
CPI.setSelectColumns(queryWrapper, Collections.singletonList(count()));
|
||||
|
||||
long count = selectCountByQuery(queryWrapper);
|
||||
page.setTotalRow(count);
|
||||
@ -633,8 +634,15 @@ public interface BaseMapper<T> {
|
||||
|
||||
int offset = page.getPageSize() * (page.getPageNumber() - 1);
|
||||
queryWrapper.limit(offset, page.getPageSize());
|
||||
try {
|
||||
// 调用内部方法,不走代理,需要主动设置 MappedStatementType
|
||||
// fixed https://gitee.com/mybatis-flex/mybatis-flex/issues/I73BP6
|
||||
MappedStatementTypes.setCurrentType(asType);
|
||||
List<R> records = selectListByQueryAs(queryWrapper, asType);
|
||||
page.setRecords(records);
|
||||
}finally {
|
||||
MappedStatementTypes.clear();
|
||||
}
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,15 +19,15 @@ public class MappedStatementTypes {
|
||||
|
||||
private static ThreadLocal<Class<?>> currentTypeTL = new ThreadLocal<>();
|
||||
|
||||
static void setCurrentType(Class<?> type){
|
||||
public static void setCurrentType(Class<?> type){
|
||||
currentTypeTL.set(type);
|
||||
}
|
||||
|
||||
static Class<?> getCurrentType(){
|
||||
public static Class<?> getCurrentType(){
|
||||
return currentTypeTL.get();
|
||||
}
|
||||
|
||||
static void clear(){
|
||||
public static void clear(){
|
||||
currentTypeTL.remove();
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.test.table.Tables.ACCOUNT;
|
||||
import static com.mybatisflex.test.table.Tables.ARTICLE;
|
||||
@ -58,39 +57,42 @@ public class EntityTestStarter {
|
||||
|
||||
// List<Account> accounts1 = myAccountMapper.selectAll();
|
||||
|
||||
QueryWrapper wrapper = QueryWrapper.create().select().from(ACCOUNT)
|
||||
.and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
||||
.and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
||||
.groupBy(ACCOUNT.ID);
|
||||
|
||||
List<Account> accounts = accountMapper.selectListByQuery(wrapper);
|
||||
System.out.println(accounts);
|
||||
|
||||
QueryWrapper wrapper1 = QueryWrapper.create().select().from(ACCOUNT)
|
||||
// .leftJoin(ARTICLE).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID).and(ACCOUNT.ID.ge(100)))
|
||||
.and(ACCOUNT.ID.ge(100).when(false).and(ACCOUNT.ID.ge(100).when(false)));
|
||||
|
||||
Page<Account> accounts1 = accountMapper.paginate(Page.of(1,1),wrapper1);
|
||||
System.out.println(accounts1);
|
||||
|
||||
|
||||
QueryWrapper wrapper2 = QueryWrapper.create().select(ACCOUNT.ID).from(ACCOUNT);
|
||||
List<Object> objects = accountMapper.selectObjectListByQuery(wrapper2);
|
||||
System.out.println(objects);
|
||||
|
||||
|
||||
Object object = accountMapper.selectObjectByQuery(wrapper2);
|
||||
System.out.println(object);
|
||||
|
||||
// QueryWrapper wrapper = QueryWrapper.create().select().from(ACCOUNT)
|
||||
// .and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
||||
// .and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
||||
// .groupBy(ACCOUNT.ID);
|
||||
//
|
||||
// List<Account> accounts = accountMapper.selectListByQuery(wrapper);
|
||||
// System.out.println(accounts);
|
||||
//
|
||||
// QueryWrapper wrapper1 = QueryWrapper.create().select().from(ACCOUNT)
|
||||
//// .leftJoin(ARTICLE).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID).and(ACCOUNT.ID.ge(100)))
|
||||
// .and(ACCOUNT.ID.ge(100).when(false).and(ACCOUNT.ID.ge(100).when(false)));
|
||||
//
|
||||
// Page<Account> accounts1 = accountMapper.paginate(Page.of(1,1),wrapper1);
|
||||
// System.out.println(accounts1);
|
||||
//
|
||||
//
|
||||
// QueryWrapper wrapper2 = QueryWrapper.create().select(ACCOUNT.ID).from(ACCOUNT);
|
||||
// List<Object> objects = accountMapper.selectObjectListByQuery(wrapper2);
|
||||
// System.out.println(objects);
|
||||
//
|
||||
//
|
||||
// Object object = accountMapper.selectObjectByQuery(wrapper2);
|
||||
// System.out.println(object);
|
||||
//
|
||||
QueryWrapper asWrapper = QueryWrapper.create()
|
||||
.select(ARTICLE.ALL_COLUMNS)
|
||||
.select(ACCOUNT.USER_NAME,ACCOUNT.AGE,ACCOUNT.BIRTHDAY)
|
||||
.from(ARTICLE)
|
||||
.leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID))
|
||||
.where(ACCOUNT.ID.ge(0));
|
||||
//
|
||||
// List<ArticleDTO> articleDTOS = accountMapper.selectListByQueryAs(asWrapper, ArticleDTO.class);
|
||||
// System.out.println(articleDTOS);
|
||||
Page<ArticleDTO> paginate = accountMapper.paginateAs(Page.of(1, 1), asWrapper, ArticleDTO.class);
|
||||
System.out.println(paginate);
|
||||
|
||||
List<ArticleDTO> articleDTOS = accountMapper.selectListByQueryAs(asWrapper, ArticleDTO.class);
|
||||
System.out.println(articleDTOS);
|
||||
|
||||
|
||||
// QueryWrapper queryWrapper = new QueryWrapper();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user