Merge branch 'feature/qt' into develop
This commit is contained in:
commit
eaaf69b09c
|
|
@ -0,0 +1,16 @@
|
|||
package com.engine.salary.util.page;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Column {
|
||||
String title;
|
||||
String dataIndex;
|
||||
String key;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.engine.salary.util.page;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DataSource {
|
||||
String key;
|
||||
String title;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.engine.salary.util.page;
|
||||
|
||||
import com.engine.salary.annotation.TableTitle;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class PageInfo<T> extends com.github.pagehelper.PageInfo<T> {
|
||||
Class<T> clazz;
|
||||
List<Column> columns = new ArrayList<>();
|
||||
List<DataSource> dataSource = new ArrayList<>();
|
||||
|
||||
public PageInfo(List<T> list) {
|
||||
super(list);
|
||||
}
|
||||
|
||||
public PageInfo(List<T> list, Class<T> clazz) {
|
||||
super(list);
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
|
||||
public List<Column> getColumns() {
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
boolean isanno = f.isAnnotationPresent(TableTitle.class);
|
||||
if (isanno) {
|
||||
TableTitle annotation = f.getAnnotation(TableTitle.class);
|
||||
String title = annotation.title();
|
||||
String dataIndex = annotation.dataIndex();
|
||||
String key = annotation.key();
|
||||
Column column = Column.builder().title(title).dataIndex(dataIndex).key(key).build();
|
||||
columns.add(column);
|
||||
}
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.engine.salary.util.page;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PageUtil {
|
||||
|
||||
public static void start(Integer pageNum, Integer pageSize) {
|
||||
pageNum = pageNum == null || pageNum <= 0 ? 1 : pageNum;
|
||||
pageSize = pageSize == null || pageSize <= 0 ? 10 : pageSize;
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
}
|
||||
|
||||
|
||||
public static <T> Page<T> buildPage(Integer pageNo, Integer pageSize) {
|
||||
pageNo = pageNo == null || pageNo <= 0 ? 1 : pageNo;
|
||||
pageSize = pageSize == null || pageSize <= 0 ? 10 : pageSize;
|
||||
return new Page(pageNo, pageSize, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param pageNo 页码(从1开始)
|
||||
* @param pageSize 每页条数
|
||||
* @param source 待分页的数据
|
||||
* @param <T> 范型制定类
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> subList(int pageNo, int pageSize, List<T> source) {
|
||||
if (CollectionUtils.isEmpty(source)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
int endIndex = pageNo * pageSize;
|
||||
int startIndex = (pageNo - 1) * pageSize;
|
||||
startIndex = startIndex < 0 ? 0 : startIndex;
|
||||
return source.subList(startIndex > source.size() ? source.size() : startIndex,
|
||||
endIndex > source.size() ? source.size() : endIndex);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue