mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
优化代码
This commit is contained in:
parent
69713b1c39
commit
0df22e3adf
@ -147,22 +147,23 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
|||||||
*/
|
*/
|
||||||
public Children pageByMain() {
|
public Children pageByMain() {
|
||||||
this.pageByMain = true;
|
this.pageByMain = true;
|
||||||
this.pageInfo = new PageInfo();
|
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主表分页
|
* 根据主表分页
|
||||||
*/
|
*/
|
||||||
public Children pageByMain(MFunction<PageInfo.PageInfoBuilder> function) {
|
public Children pageByMain(MFunction<PageInfo> function) {
|
||||||
this.pageByMain = true;
|
this.pageByMain = true;
|
||||||
PageInfo.PageInfoBuilder apply = function.apply(PageInfo.builder());
|
function.apply(getPageInfo());
|
||||||
this.pageInfo = apply.build();
|
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageInfo getPageInfo() {
|
public PageInfo getPageInfo() {
|
||||||
return pageInfo == null ? new PageInfo() : pageInfo;
|
if (pageInfo == null) {
|
||||||
|
pageInfo = new PageInfo();
|
||||||
|
}
|
||||||
|
return pageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,22 +182,23 @@ public abstract class KtAbstractLambdaWrapper<T, Children extends KtAbstractLamb
|
|||||||
*/
|
*/
|
||||||
public Children pageByMain() {
|
public Children pageByMain() {
|
||||||
this.pageByMain = true;
|
this.pageByMain = true;
|
||||||
this.pageInfo = new PageInfo();
|
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主表分页
|
* 根据主表分页
|
||||||
*/
|
*/
|
||||||
public Children pageByMain(MFunction<PageInfo.PageInfoBuilder> function) {
|
public Children pageByMain(MFunction<PageInfo> function) {
|
||||||
this.pageByMain = true;
|
this.pageByMain = true;
|
||||||
PageInfo.PageInfoBuilder apply = function.apply(PageInfo.builder());
|
function.apply(getPageInfo());
|
||||||
this.pageInfo = apply.build();
|
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageInfo getPageInfo() {
|
public PageInfo getPageInfo() {
|
||||||
return pageInfo == null ? new PageInfo() : pageInfo;
|
if (pageInfo == null) {
|
||||||
|
pageInfo = new PageInfo();
|
||||||
|
}
|
||||||
|
return pageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
import com.github.yulichang.adapter.AdapterHelper;
|
import com.github.yulichang.adapter.AdapterHelper;
|
||||||
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||||
import com.github.yulichang.interceptor.pagination.PageInnerInterceptor;
|
import com.github.yulichang.interceptor.pagination.PageInnerInterceptor;
|
||||||
import org.apache.ibatis.logging.Log;
|
import org.apache.ibatis.logging.Log;
|
||||||
|
@ -182,22 +182,23 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
|||||||
*/
|
*/
|
||||||
public Children pageByMain() {
|
public Children pageByMain() {
|
||||||
this.pageByMain = true;
|
this.pageByMain = true;
|
||||||
this.pageInfo = new PageInfo();
|
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主表分页
|
* 根据主表分页
|
||||||
*/
|
*/
|
||||||
public Children pageByMain(MFunction<PageInfo.PageInfoBuilder> function) {
|
public Children pageByMain(MFunction<PageInfo> function) {
|
||||||
this.pageByMain = true;
|
this.pageByMain = true;
|
||||||
PageInfo.PageInfoBuilder apply = function.apply(PageInfo.builder());
|
function.apply(getPageInfo());
|
||||||
this.pageInfo = apply.build();
|
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageInfo getPageInfo() {
|
public PageInfo getPageInfo() {
|
||||||
return pageInfo == null ? new PageInfo() : pageInfo;
|
if (pageInfo == null) {
|
||||||
|
pageInfo = new PageInfo();
|
||||||
|
}
|
||||||
|
return pageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ import java.io.Serializable;
|
|||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PageInfo implements Serializable {
|
public class PageInfo implements Serializable {
|
||||||
@ -19,32 +21,4 @@ public class PageInfo implements Serializable {
|
|||||||
private IPage<?> innerPage;
|
private IPage<?> innerPage;
|
||||||
|
|
||||||
private String countSelectSql;
|
private String countSelectSql;
|
||||||
|
|
||||||
public static PageInfoBuilder builder() {
|
|
||||||
return new PageInfoBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static class PageInfoBuilder {
|
|
||||||
private IPage<?> innerPage;
|
|
||||||
private String countSelectSql;
|
|
||||||
|
|
||||||
PageInfoBuilder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public PageInfoBuilder innerPage(IPage<?> innerPage) {
|
|
||||||
this.innerPage = innerPage;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PageInfoBuilder countSelectSql(String countSelectSql) {
|
|
||||||
this.countSelectSql = countSelectSql;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PageInfo build() {
|
|
||||||
return new PageInfo(this.innerPage, this.countSelectSql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class PageByMainTest {
|
|||||||
.orderByDesc(UserDO::getId)
|
.orderByDesc(UserDO::getId)
|
||||||
.groupBy(UserDO::getId)
|
.groupBy(UserDO::getId)
|
||||||
.logicDelToOn()
|
.logicDelToOn()
|
||||||
.pageByMain(f -> f.countSelectSql("1"));
|
.pageByMain(f -> f.setCountSelectSql("1"));
|
||||||
|
|
||||||
Page<UserDTO> page = wrapper.page(new Page<>(1, 8), UserDTO.class);
|
Page<UserDTO> page = wrapper.page(new Page<>(1, 8), UserDTO.class);
|
||||||
page.getRecords().forEach(System.out::println);
|
page.getRecords().forEach(System.out::println);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user