DalPage :
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
public class DalPage {
private static final long serialVersionUID = -8123039538589235324L;
/**
* 适用于排序后取第一条数据的查询
*
* @return
*/
public static DalPage getOneInstance() {
DalPage dalPage = new DalPage();
dalPage.setPageSize(1);
dalPage.setCurrentPage(1);
return dalPage;
}
/**
* 创建实例
*
* @param pageSize
* @param currentPage
* @return
*/
public static DalPage createInstance(int pageSize, int currentPage) {
DalPage dalPage = new DalPage();
dalPage.setPageSize(pageSize);
dalPage.setCurrentPage(currentPage);
return dalPage;
}
/**
* 创建实例
*
* @param pageSize
* @return
*/
public static DalPage createInstance(int pageSize) {
DalPage dalPage = new DalPage();
dalPage.setPageSize(pageSize);
dalPage.setCurrentPage(1);
return dalPage;
}
/**
* The Current page.
*/
protected int currentPage = 1;
/**
* The Page size.
*/
protected int pageSize = 10;
/**
* The Count.
*/
protected long count;
/**
* The Pages.
*/
protected int pages;
/**
* The Index.
*/
protected int index;
public void setPages(int pages) {
this.pages = pages;
}
public void setIndex(int index) {
this.index = index;
}
/**
* Instantiates a new Dal page.
*/
public DalPage() {
}
/**
* 获取当前页面 <br>
*
* @return the current page
*/
public int getCurrentPage() {
return this.currentPage;
}
/**
* 设置当前页面 <br>
*
* @param currentPage the current page
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
/**
* 获取页面大小 <br>
*
* @return the page size
*/
public int getPageSize() {
return this.pageSize;
}
/**
* 设置页面大小 <br>
*
* @param pageSize the page size
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
/**
* 获取数量 <br>
*
* @return the count
*/
public long getCount() {
return this.count;
}
/**
* 设置数量 <br>
*
* @param count the count
*/
public void setCount(long count) {
this.count = count;
if (count > 0L) {
this.pages = (int) (this.count / (long) this.pageSize);
if (this.count % (long) this.pageSize > 0L) {
++this.pages;
}
if (this.currentPage > this.pages) {
this.currentPage = this.pages;
}
this.index = (this.currentPage - 1) * this.pageSize;
}
}
/**
* 获取Pages <br>
*
* @return the pages
*/
public int getPages() {
return this.pages;
}
/**
* 获取Indexes <br>
*
* @return the index
*/
public int getIndex() {
return this.index;
}
/**
* 获取PageBar <br>
*
* @return the page bar
*/
public DalPage.PageBar getPageBar() {
return new DalPage.PageBar();
}
/**
* 为了页面相关的内容设置PageBar <br>
*
* @author 18020760
*/
public class PageBar {
private static final int BLOCK_LENGTH = 5;
private List<Integer> clickBlocks;
private int start;
private int end;
/**
* 默认构造函数 <br>
*/
PageBar() {
if (DalPage.this.pages == 0) {
this.clickBlocks = Collections.emptyList();
}
this.start = DalPage.this.currentPage - 2 < 1 ? 1 : DalPage.this.currentPage - 2;
this.end = this.start + 5 - 1;
if (this.end > DalPage.this.pages) {
this.end = DalPage.this.pages;
this.start = this.end - 5 + 1;
}
if (this.start < 1) {
this.start = 1;
}
this.clickBlocks = new LinkedList();
for (int i = this.start; i <= this.end; ++i) {
this.clickBlocks.add(i);
}
}
/**
* 获取点击块 <br>
*
* @return the click blocks
*/
public List<Integer> getClickBlocks() {
return this.clickBlocks;
}
/**
* 获取之前的点击块 <br>
*
* @return the boolean
*/
public boolean hasPreviousBar() {
return DalPage.this.pages > 0 && this.start > 1;
}
/**
* 获取之后的点击块 <br>
*
* @return the boolean
*/
public boolean hasNextBar() {
return DalPage.this.pages > 0 && this.end < DalPage.this.pages;
}
}
}
PageResultVO:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* 分页信息前端模型
* Created by 17032906 on 2017/9/4.
*
* @param <T> the type parameter
*/
public class PageResultVO<T> {
/**
* 分页信息
*/
private DalPage page;
/**
* 分页数据
*/
private List<T> list;
private Object collectData;
public Object getCollectData() {
return collectData;
}
public void setCollectData(Object collectData) {
this.collectData = collectData;
}
/**
* Instantiates a new Page result vo.
*
* @param page the page
* @param list the list
*/
public PageResultVO(DalPage page, List<T> list) {
this.page = page;
if (list != null) {
this.list = list;
} else {
this.list = new ArrayList<>();
}
}
public PageResultVO(DalPage page, List<T> list, Object collectData) {
this.page = page;
if (list != null) {
this.list = list;
} else {
this.list = new ArrayList<>();
}
if (null != collectData){
this.collectData = collectData;
}else {
this.collectData = new HashMap();
}
}
/**
* Gets page.
*
* @return the page
*/
public DalPage getPage() {
return page;
}
/**
* Sets page.
*
* @param page the page
*/
public void setPage(DalPage page) {
this.page = page;
}
/**
* Gets list.
*
* @return the list
*/
public List<T> getList() {
return list;
}
/**
* Sets list.
*
* @param list the list to set
*/
public void setList(List<T> list) {
this.list = list;
}
}
ResponseUtils :
/**
* 返回模型工具类
*/
public final class ResponseUtils {
private ResponseUtils() {
}
/**
* 成功不带数据
*
* @return response mode
*/
public static ResponseMode success() {
return new ResponseMode(HttpResponseCodeEnum.SUCCESS.getCode(),
HttpResponseCodeEnum.SUCCESS.getMessage());
}
/**
* 成功带数据
*
* @param data the data
* @return response mode
*/
public static ResponseMode success(Object data) {
return new ResponseMode(HttpResponseCodeEnum.SUCCESS.getCode(),
HttpResponseCodeEnum.SUCCESS.getMessage(), data);
}
/**
* 失败带消息
*
* @param msg the msg
* @return response mode
*/
public static ResponseMode fail(String msg){
return new ResponseMode(HttpResponseCodeEnum.FAILURE.getCode(),
msg);
}
/**
* 失败带数据和消息
*
* @param msg the msg
* @param data the data
* @return response mode
*/
public static ResponseMode fail(String msg, Object data){
return new ResponseMode(HttpResponseCodeEnum.FAILURE.getCode(),
msg, data);
}
/**
* 失败带消息
*
* @param codeEnum the code enum
* @return response mode
*/
public static ResponseMode fail(HttpResponseCodeEnum codeEnum){
return new ResponseMode(codeEnum.getCode(), codeEnum.getMessage());
}
/**
* 无权限
*
* @return response mode
*/
public static ResponseMode nopermission(){
return new ResponseMode(HttpResponseCodeEnum.NOPERMISSION.getCode(), HttpResponseCodeEnum.NOPERMISSION.getMessage());
}
/**
* 未登录
*
* @return response mode
*/
public static ResponseMode notlogin(){
return new ResponseMode(HttpResponseCodeEnum.NOTLOGIN.getCode(),
HttpResponseCodeEnum.NOTLOGIN.getMessage());
}
}
ResponseMode :
/**
* 返回模型
* Created by 17010763 on 2017/3/26.
*/
public class ResponseMode {
/**
* 响应码
*/
private String ret;
/**
* 提示消息
*/
private String msg;
/**
* 返回数据
*/
private Object data;
/**
* 构造方法
*
* @param ret the ret
* @param msg the msg
*/
public ResponseMode(String ret, String msg) {
this.ret = ret;
this.msg = msg;
}
/**
* 构造方法
*
* @param ret the ret
* @param msg the msg
* @param data the data
*/
public ResponseMode(String ret, String msg, Object data) {
this.ret = ret;
this.msg = msg;
this.data = data;
}
/**
* getter
*
* @return ret ret
*/
public String getRet() {
return ret;
}
/**
* setter
*
* @param ret the ret
*/
public void setRet(String ret) {
this.ret = ret;
}
/**
* getter
*
* @return msg msg
*/
public String getMsg() {
return msg;
}
/**
* setter
*
* @param msg the msg
*/
public void setMsg(String msg) {
this.msg = msg;
}
/**
* getter
*
* @return data data
*/
public Object getData() {
return data;
}
/**
* setter
*
* @param data the data
*/
public void setData(Object data) {
this.data = data;
}
}
HttpResponseCodeEnum:
/**
* 相应码枚举类
*/
public enum HttpResponseCodeEnum {
/**
* Success http response code enum.
*/
SUCCESS("0000", "请求成功"),
/**
* Notlogin http response code enum.
*/
NOTLOGIN("0001", "未登录"),
/**
* Nopermission http response code enum.
*/
NOPERMISSION("0002","无权限"),
/**
* Failure http response code enum.
*/
FAILURE("0003","请求失败");
private String code;
private String message;
/**
* 构造器
* @param code
* @param message
*/
HttpResponseCodeEnum(String code, String message) {
this.code = code;
this.message = message;
}
/**
* getter
*
* @return code code
*/
public String getCode() {
return code;
}
/**
* getter
*
* @return message message
*/
public String getMessage() {
return message;
}
}