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

master
wayn 4 years ago
parent 864015be76
commit d121ee0706

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

@ -2,6 +2,7 @@ package com.wayn.common.base.controller;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.constant.Constants; import com.wayn.common.constant.Constants;
@ -15,6 +16,7 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; 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() { 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) { protected <T> Page<T> getPage(int pageNumber) {
return getPage(pageNumber, 15); return getPage(pageNumber, 15);
@ -96,20 +99,37 @@ public class BaseController {
* *
* </p> * </p>
* *
* @param pageNumber * @param pageNumber
* @param pageSize * @param pageSize
* @param <T> * @param <T>
* @return * @return
*/ */
protected <T> Page<T> getPage(int pageNumber, int pageSize) { protected <T> Page<T> getPage(int pageNumber, int pageSize) {
return new Page<T>(pageNumber, 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 * url
* *
* @param url * @param url
* @return * @return
*/ */
protected String redirectTo(String url) { protected String redirectTo(String url) {
StringBuffer rto = new StringBuffer("redirect:"); StringBuffer rto = new StringBuffer("redirect:");
@ -121,7 +141,7 @@ public class BaseController {
* JSON * JSON
* *
* @param object * @param object
* @return * @return json
*/ */
protected String toJson(Object object) { protected String toJson(Object object) {
return JSON.toJSONString(object, SerializerFeature.BrowserCompatible); return JSON.toJSONString(object, SerializerFeature.BrowserCompatible);
@ -132,7 +152,8 @@ public class BaseController {
* *
* @param object * @param object
* @param format * @param format
* @return * @return json
*
*/ */
protected String toJson(Object object, String format) { protected String toJson(Object object, String format) {
if (format == null) { if (format == null) {

Loading…
Cancel
Save