package com.visec.utils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* datatable分页工具
*/
public class DataTablePageBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
//输入必要属性
private int draw; //dataTable必要参数
private int start = 0; //开始的记录数
private int length = 10; //每页显示记录数
private Search search; //搜索栏
private List<Order> order; //排序列表
private List<Columns> columns; //数据属性列表
//输出必要属性
private int recordsTotal; //总页数
private int recordsFiltered; //过滤后总页数
private List<?> data; //封装结果
private int dataCount; //总记录数
//自定义属性
private Object priParam; //私有自定义属性
private String contHql; //统计Hql语句
private String findHql; //查询Hql语句
public Search getSearch() {
return search;
}
public void setSearch(Search search) {
this.search = search;
}
public List<Order> getOrder() {
return order;
}
public void setOrder(List<Order> order) {
this.order = order;
}
public List<Columns> getColumns() {
return columns;
}
public void setColumns(List<Columns> columns) {
this.columns = columns;
}
public int getDraw() {
return draw;
}
public void setDraw(int draw) {
this.draw = draw;
}
public int getRecordsTotal() {
return recordsTotal;
}
public int getRecordsFiltered() {
return recordsFiltered;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = (length <= 0) ? 1 : length;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = (start < 0) ? 0 : start;
}
public List<?> getData() {
return (data != null ) ? data : new ArrayList<Object>() ;
}
public void setData(List<?> data) {
this.data = data;
}
public int getDataCount() {
return dataCount;
}
public void setDataCount(int dataCount) {
this.dataCount = dataCount;
this.recordsTotal = dataCount;
this.recordsFiltered = dataCount;
}
public Object getPriParam() {
return priParam;
}
public void setPriParam(Object priParam) {
this.priParam = priParam;
}
public String getContHql() {
return contHql;
}
public void setContHql(String contHql) {
this.contHql = contHql;
}
public String getFindHql() {
return findHql;
}
public void setFindHql(String findHql) {
this.findHql = findHql;
}
/**
* 搜索内部类
*/
public static class Search implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Boolean regex;
private String value;
public Boolean getRegex() {
return regex;
}
public void setRegex(Boolean regex) {
this.regex = regex;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
/**
* 排序类
*/
public static class Order implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer column;
private String dir;
public Integer getColumn() {
return column;
}
public void setColumn(Integer column) {
this.column = column;
}
public String getDir() {
return dir;
}
public void setDir(String dir) {
this.dir = dir;
}
}
/**
* 列表类
*/
public static class Columns implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String data;
private String name;
private Boolean orderable;
private Boolean searchable;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getOrderable() {
return orderable;
}
public void setOrderable(Boolean orderable) {
this.orderable = orderable;
}
public Boolean getSearchable() {
return searchable;
}
public void setSearchable(Boolean searchable) {
this.searchable = searchable;
}
}
public String countHql(DataTablePageBean pageBean){
if( pageBean.getSearch()!=null && !pageBean.getSearch().getValue().equals("")){
return (contHql.contains("where"))
? contHql+" and like %"+pageBean.getSearch().getValue()+"%"
: contHql+"where like %"+pageBean.getSearch().getValue()+"%";
}
return contHql;
}
public String findHql(DataTablePageBean pageBean){
if(pageBean.getColumns()!=null){
Integer columnNum = pageBean.getOrder().get(0).getColumn();
String order = pageBean.getOrder().get(0).getDir();
String fieldName = pageBean.getColumns().get(columnNum).getName();
String fHql = countHql(pageBean)+" ORDER BY "+fieldName+" "+order;
return fHql;
}
return findHql;
}
}
以上是DataTablePageBean对象
@At
public Object fetchUserList(@Param("..") DataTablePageBean pageBean){
userService.fetchUserList(pageBean);
return ajaxOk(pageBean);
}
这样可以获取到DataTablePageBean, 但是获取不到Search,报空指针异常