分页修改

hehai
rong.liu 4 years ago
parent 700a1db096
commit 0577e59e11
  1. 25
      pom.xml
  2. 2
      src/main/java/com/msdw/tms/TmsApplication.java
  3. 20
      src/main/java/com/msdw/tms/controller/AchievementManagementController.java
  4. 7
      src/main/java/com/msdw/tms/service/AchievementManagementService.java
  5. 37
      src/main/java/com/msdw/tms/service/impl/AchievementManagementServiceImpl.java
  6. 113
      src/main/java/com/msdw/tms/util/PageUtils.java

@ -220,10 +220,31 @@
<version>2.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
<!--使用spring boot2整合 pagehelper-spring-boot-starter必须排除一下依赖
因为pagehelper-spring-boot-starter也已经在pom依赖了mybatis与mybatis-spring
所以会与mybatis-plus-boot-starter中的mybatis与mybatis-spring发生冲突
-->
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>

@ -6,7 +6,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling//定时任务
//@EnableScheduling//定时任务
@SpringBootApplication
public class TmsApplication extends SpringBootServletInitializer {

@ -1,6 +1,8 @@
package com.msdw.tms.controller;
import com.github.pagehelper.PageInfo;
import com.msdw.tms.api.AchievementManagementApi;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.*;
import com.msdw.tms.entity.vo.AchievementManagementVO;
@ -8,13 +10,11 @@ import com.msdw.tms.entity.vo.ResultsVo;
import com.msdw.tms.service.AchievementManagementService;
import com.msdw.tms.service.ProjectRecordService;
import com.msdw.tms.util.ListPageUtil;
import com.msdw.tms.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
@ -91,12 +91,10 @@ public class AchievementManagementController implements AchievementManagementApi
if (endTime != null) {
vo.setEndTime(endTime);
}
List<ResultsEntity> result = service.list(vo, page, size);
PageInfo<ResultsEntity> result = service.list(vo, page, size);
ListPageUtil<ResultsEntity> listPageUtil = new ListPageUtil<ResultsEntity>(result, page, size);
List<ResultsEntity> pagedList = listPageUtil.getPagedList();
PageUtils pageUtils = new PageUtils(pagedList, result.size(), page, size);
return R.ok().put("data", pageUtils);
return R.ok().put("data", result);
}
/**
@ -126,12 +124,8 @@ public class AchievementManagementController implements AchievementManagementApi
if (endTime != null) {
vo.setEndTime(endTime);
}
List<ResultsEntity> result = service.newList(vo, page, size);
/*return R.ok().put("data", result);*/
ListPageUtil<ResultsEntity> listPageUtil = new ListPageUtil<ResultsEntity>(result, page, size);
List<ResultsEntity> pagedList = listPageUtil.getPagedList();
PageUtils pageUtils = new PageUtils(pagedList, result.size(), page, size);
return R.ok().put("data", pageUtils);
PageInfo<ResultsEntity> result = service.newList(vo, page, size);
return R.ok().put("data", result);
}
/**

@ -1,16 +1,15 @@
package com.msdw.tms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageInfo;
import com.msdw.tms.common.utils.R;
import com.msdw.tms.entity.ExperimentalReportEntity;
import com.msdw.tms.entity.ExperimentalTeachingEntity;
import com.msdw.tms.entity.ReportEntity;
import com.msdw.tms.entity.ResultsEntity;
import com.msdw.tms.entity.vo.AchievementManagementVO;
import com.msdw.tms.entity.vo.ResultsVo;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
public interface AchievementManagementService extends IService<ExperimentalReportEntity> {
@ -21,10 +20,10 @@ public interface AchievementManagementService extends IService<ExperimentalRepor
//查询知道老师
R getTeacher(Integer projectId);
List<ResultsEntity> list(ResultsVo vo, Integer page, Integer size);
PageInfo<ResultsEntity> list(ResultsVo vo, Integer page, Integer size);
//查询实验教学列表
List<ResultsEntity> newList(ResultsVo vo, Integer page, Integer size);
PageInfo<ResultsEntity> newList(ResultsVo vo, Integer page, Integer size);
List<ReportEntity> reportList(ResultsVo vo, Integer page, Integer size);

@ -3,6 +3,8 @@ package com.msdw.tms.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.msdw.tms.common.utils.Constant;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.common.utils.R;
@ -88,10 +90,12 @@ public class AchievementManagementServiceImpl extends ServiceImpl<AchievementMan
* @return
*/
@Override
public List<ResultsEntity> list(ResultsVo vo, Integer page, Integer size) {
public PageInfo<ResultsEntity> list(ResultsVo vo, Integer page, Integer size) {
//使用分页插件,核心代码就这一行
PageHelper.startPage(page, size);
List<ResultsEntity> list = achievementManagementDao.list(vo);
PageInfo info = new PageInfo(list);
for (ResultsEntity entity : list) {
Integer number = achievementManagementDao.getImitationAchievement(entity.getProjectId()).size();
@ -100,11 +104,30 @@ public class AchievementManagementServiceImpl extends ServiceImpl<AchievementMan
ProjectHiddenEntity hiddenEntity = projectHiddenDao.selectByProjectId(entity.getProjectId());
entity.setProjectHiddenEntity(hiddenEntity);
}
/*
Date begin = new Date();
list.parallelStream().forEach(x -> {
x.setNumber(achievementManagementDao.getImitationAchievement(x.getProjectId()).size());
x.setProjectHiddenEntity(projectHiddenDao.selectByProjectId(x.getProjectId()));
});
Date end = new Date();
// System.out.println("时间1:" + (end.getTime() - begin.getTime()));
Date begin1 = new Date();
for (ResultsEntity entity : list) {
Integer number = achievementManagementDao.getImitationAchievement(entity.getProjectId()).size();
entity.setNumber(number);
ProjectHiddenEntity hiddenEntity = projectHiddenDao.selectByProjectId(entity.getProjectId());
entity.setProjectHiddenEntity(hiddenEntity);
}
Date end1 = new Date();*/
//System.out.println("时间2:" + (end1.getTime() - begin1.getTime()));
return list;
// PageInfo<ResultsEntity> ret = new PageInfo<>();
return info;
}
@Override
@ -114,7 +137,9 @@ public class AchievementManagementServiceImpl extends ServiceImpl<AchievementMan
}
@Override
public List<ResultsEntity> newList(ResultsVo vo, Integer page, Integer size) {
public PageInfo<ResultsEntity> newList(ResultsVo vo, Integer page, Integer size) {
//使用分页插件,核心代码就这一行
PageHelper.startPage(page, size);
List<ResultsEntity> newList = achievementManagementDao.newList(vo);
for (ResultsEntity entity : newList) {
Integer number = achievementManagementDao.getTeachAchievement(entity.getId()).size();
@ -123,7 +148,9 @@ public class AchievementManagementServiceImpl extends ServiceImpl<AchievementMan
ProjectHiddenEntity hiddenEntity = projectHiddenDao.selectByTeachId(entity.getId());
entity.setProjectHiddenEntity(hiddenEntity);
}
return newList;
PageInfo info = new PageInfo(newList);
return info;
}

@ -1,113 +0,0 @@
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
* <p>
* https://www.renren.io
* <p>
* 版权所有侵权必究
*/
package com.msdw.tms.util;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 分页工具类
*
* @author Mark sunlightcs@gmail.com
*/
@Data
public class PageUtils implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 总记录数
*/
private int totalCount;
/**
* 每页记录数
*/
private int pageSize;
/**
* 总页数
*/
private int totalPage;
/**
* 当前页数
*/
private int currPage;
/**
* 列表数据
*/
private List<?> list;
/**
* 分页
*
* @param list 列表数据
* @param totalCount 总记录数
* @param pageSize 每页记录数
* @param currPage 当前页数
*/
public PageUtils(List<?> list, int totalCount, int pageSize, int currPage) {
this.list = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currPage = currPage;
this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
}
/**
* 分页
*/
public PageUtils(IPage<?> page) {
this.list = page.getRecords();
this.totalCount = (int) page.getTotal();
this.pageSize = (int) page.getSize();
this.currPage = (int) page.getCurrent();
this.totalPage = (int) page.getPages();
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public List<?> getList() {
return list;
}
public void setList(List<?> list) {
this.list = list;
}
}
Loading…
Cancel
Save