All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.web.easyui.PivotUtil Maven / Gradle / Ivy

Go to download

本项目主要弥补在使用mybatis3+springmvc+jquery easyui快速搭建web应用系统是遇到的框架不足. 主要工作包括: 1,扩展了ApplicationContextAware,通过单例注入spring容器,提供spring容器外的bean获取方法 2,扩展了apache shiro框架,统一了安全结构 3,扩展了mybatis3拦截器,在两个拦截器中自动完成分页注入,实现内存分页。 4,分页设计数据库方言 5,提供了一个easyuigrid的模型 6,提供了java泛型的jstl 7, xml工具包等一些小工具

The newest version!
package net.sourceforge.web.easyui;

import javax.servlet.http.HttpServletRequest;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;

/**
 * 处理分页,排序,过滤等
 * 
 * @author Alex
 *
 */
public class PivotUtil {
	private final static Gson gson = new Gson();

	private PivotUtil() {
	}

	public static  PivotPage parse(final HttpServletRequest req) {
		int rowsPerPage = 10;// default
		try {
			rowsPerPage = Integer.parseInt(req.getParameter("rows"));//
		} catch (NumberFormatException e) {
			// does not provide, use default page size
		}

		int currentPage = 1;
		try {
			currentPage = Integer.parseInt(req.getParameter("page"));//
		} catch (NumberFormatException e) {
			// does not provide, from page 1
		}
		PivotPage pivot = new PivotPage(currentPage, rowsPerPage);

		// 支持多个参数sort=?&sort=?
		String[] sortArray = req.getParameterValues("sort");// columns
		if (sortArray == null)
			sortArray = req.getParameterValues("sortIndex");// 向下兼容
		String[] orderArray = req.getParameterValues("order");
		if (orderArray == null)
			orderArray = req.getParameterValues("sortOrder");// 向下兼容

		if (sortArray != null && sortArray.length > 0) {
			// 每个sort参数可以使用逗号分割
			for (int i = 0; i < sortArray.length; i++) {
				String[] sorts = sortArray[i].split(",");
				String[] orders = orderArray[i].split(",");
				for (int j = 0; j < sorts.length; j++) {
					if ("".equalsIgnoreCase(orders[j]) || "NULL".equalsIgnoreCase(orders[j]))
						continue;
					pivot.addSortParam(sorts[j], orders[j]);
				}
			}
		}
		String fr = req.getParameter("filterRules");
		if (fr != null && fr.length() > 0) {
			JsonParser parser = new JsonParser();
			JsonArray array = parser.parse(fr).getAsJsonArray();
			for (int i = 0; i < array.size(); i++) {
				pivot.getFilterRule().add(gson.fromJson(array.get(i), FilterRule.class));
			}
		}

		req.setAttribute("page", pivot);
		return pivot;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy