feat(后台管理): 代码优化

master
wayn 4 years ago
parent 864015be76
commit d121ee0706

@ -54,12 +54,7 @@ public class ColumnController extends BaseController {
}
return columnVO;
}).collect(Collectors.toList());
Page<ColumnVO> formatPage = getPage();
formatPage.setRecords(columnVOS);
formatPage.setTotal(columnIPage.getTotal());
formatPage.setPages(columnIPage.getPages());
formatPage.setSize(columnIPage.getSize());
return R.success().add("page", formatPage);
return R.success().add("page", formatPage(columnIPage, columnVOS));
}
@PostMapping

@ -2,6 +2,7 @@ package com.wayn.common.base.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.constant.Constants;
@ -15,6 +16,7 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
*
@ -49,9 +51,9 @@ public class BaseController {
}
/**
* <p>
*
* </p>
* @param <T>
* @return
*/
protected <T> Page<T> getPage() {
//设置通用分页
@ -83,9 +85,10 @@ public class BaseController {
/**
* <p>
*
* </p>
* @param pageNumber
* @param <T>
* @return
*/
protected <T> Page<T> getPage(int pageNumber) {
return getPage(pageNumber, 15);
@ -96,20 +99,37 @@ public class BaseController {
*
* </p>
*
* @param pageNumber
* @param pageSize
* @param pageNumber
* @param pageSize
* @param <T>
* @return
* @return
*/
protected <T> Page<T> getPage(int pageNumber, int pageSize) {
return new Page<T>(pageNumber, pageSize);
}
/**
*
*
* @param iPage
* @param list
* @return
*/
protected <E, T> IPage<T> formatPage(IPage<E> iPage, List<T> list) {
Page<T> formatPage = getPage();
formatPage.setRecords(list);
formatPage.setTotal(iPage.getTotal());
formatPage.setCurrent(iPage.getCurrent());
formatPage.setPages(iPage.getPages());
formatPage.setSize(iPage.getSize());
return formatPage;
}
/**
* url
*
* @param url
* @return
* @return
*/
protected String redirectTo(String url) {
StringBuffer rto = new StringBuffer("redirect:");
@ -121,7 +141,7 @@ public class BaseController {
* JSON
*
* @param object
* @return
* @return json
*/
protected String toJson(Object object) {
return JSON.toJSONString(object, SerializerFeature.BrowserCompatible);
@ -132,7 +152,8 @@ public class BaseController {
*
* @param object
* @param format
* @return
* @return json
*
*/
protected String toJson(Object object, String format) {
if (format == null) {

Loading…
Cancel
Save