|
|
@ -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) {
|
|
|
|