From 0577e59e111a1cc2c75d46faf0c0f0ebb88f54fd Mon Sep 17 00:00:00 2001 From: "rong.liu" Date: Thu, 18 Mar 2021 10:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 25 +++- .../java/com/msdw/tms/TmsApplication.java | 2 +- .../AchievementManagementController.java | 20 ++-- .../service/AchievementManagementService.java | 7 +- .../AchievementManagementServiceImpl.java | 37 +++++- .../java/com/msdw/tms/util/PageUtils.java | 113 ------------------ 6 files changed, 66 insertions(+), 138 deletions(-) delete mode 100644 src/main/java/com/msdw/tms/util/PageUtils.java diff --git a/pom.xml b/pom.xml index 1888f60..521842c 100644 --- a/pom.xml +++ b/pom.xml @@ -220,10 +220,31 @@ 2.1.1 + com.github.pagehelper - pagehelper - 5.1.2 + pagehelper-spring-boot-starter + 1.2.10 + + + + org.mybatis + mybatis + + + org.mybatis + mybatis-spring + + + + + + com.baomidou + mybatis-plus-boot-starter + 3.2.0 diff --git a/src/main/java/com/msdw/tms/TmsApplication.java b/src/main/java/com/msdw/tms/TmsApplication.java index e2715d0..1e5e101 100644 --- a/src/main/java/com/msdw/tms/TmsApplication.java +++ b/src/main/java/com/msdw/tms/TmsApplication.java @@ -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 { diff --git a/src/main/java/com/msdw/tms/controller/AchievementManagementController.java b/src/main/java/com/msdw/tms/controller/AchievementManagementController.java index db82573..15e801d 100644 --- a/src/main/java/com/msdw/tms/controller/AchievementManagementController.java +++ b/src/main/java/com/msdw/tms/controller/AchievementManagementController.java @@ -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 result = service.list(vo, page, size); + PageInfo result = service.list(vo, page, size); - ListPageUtil listPageUtil = new ListPageUtil(result, page, size); - List 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 result = service.newList(vo, page, size); - /*return R.ok().put("data", result);*/ - ListPageUtil listPageUtil = new ListPageUtil(result, page, size); - List pagedList = listPageUtil.getPagedList(); - PageUtils pageUtils = new PageUtils(pagedList, result.size(), page, size); - return R.ok().put("data", pageUtils); + PageInfo result = service.newList(vo, page, size); + return R.ok().put("data", result); } /** diff --git a/src/main/java/com/msdw/tms/service/AchievementManagementService.java b/src/main/java/com/msdw/tms/service/AchievementManagementService.java index dfd3bc2..275b341 100644 --- a/src/main/java/com/msdw/tms/service/AchievementManagementService.java +++ b/src/main/java/com/msdw/tms/service/AchievementManagementService.java @@ -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 { @@ -21,10 +20,10 @@ public interface AchievementManagementService extends IService list(ResultsVo vo, Integer page, Integer size); + PageInfo list(ResultsVo vo, Integer page, Integer size); //查询实验教学列表 - List newList(ResultsVo vo, Integer page, Integer size); + PageInfo newList(ResultsVo vo, Integer page, Integer size); List reportList(ResultsVo vo, Integer page, Integer size); diff --git a/src/main/java/com/msdw/tms/service/impl/AchievementManagementServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/AchievementManagementServiceImpl.java index 065cf3a..b21b766 100644 --- a/src/main/java/com/msdw/tms/service/impl/AchievementManagementServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/AchievementManagementServiceImpl.java @@ -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 list(ResultsVo vo, Integer page, Integer size) { - + public PageInfo list(ResultsVo vo, Integer page, Integer size) { + //使用分页插件,核心代码就这一行 + PageHelper.startPage(page, size); List 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 { + 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())); + // PageInfo ret = new PageInfo<>(); - return list; + return info; } @Override @@ -114,7 +137,9 @@ public class AchievementManagementServiceImpl extends ServiceImpl newList(ResultsVo vo, Integer page, Integer size) { + public PageInfo newList(ResultsVo vo, Integer page, Integer size) { + //使用分页插件,核心代码就这一行 + PageHelper.startPage(page, size); List newList = achievementManagementDao.newList(vo); for (ResultsEntity entity : newList) { Integer number = achievementManagementDao.getTeachAchievement(entity.getId()).size(); @@ -123,7 +148,9 @@ public class AchievementManagementServiceImpl extends ServiceImpl - * https://www.renren.io - *

- * 版权所有,侵权必究! - */ - -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; - } - -}