request工具类

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

/**
 * requet工具类
 * @author 
 */
public abstract class RequestUtils {

	public static Boolean getBoolParam(HttpServletRequest request, String name) {
		String val = request.getParameter(name);
		if (StringUtils.isBlank(val))
			return null;
		try {
			return Boolean.parseBoolean(val);
		} catch (Exception e) {
			return null;
		}
	}

	public static Integer getIntParam(HttpServletRequest request, String name) {
		String val = request.getParameter(name);
		if (StringUtils.isBlank(val))
			return null;
		try {
			return Integer.parseInt(val);
		} catch (Exception e) {
			return null;
		}
	}

	public static Float getFloatParam(HttpServletRequest request, String name) {
		String val = request.getParameter(name);
		if (StringUtils.isBlank(val))
			return null;
		try {
			return Float.parseFloat(val);
		} catch (Exception e) {
			return null;
		}
	}

	public static Integer[] getIntArrParam(HttpServletRequest request, String name) {
		String[] values = request.getParameterValues(name);
		if(values == null) {
			return null;
		}
		Integer[] intValues = new Integer[values.length];
		for(int index = 0; index < values.length; index++) {
			intValues[index] = Integer.parseInt(values[index]);
		}
		return intValues;
	}

	public static Integer[] getIntArrSplitParam(HttpServletRequest request,
			String name, String split) {
		String value = request.getParameter(name);
		if(value == null) {
			return null;
		}
		String[] strValues = value.split(split);
		Integer[] intValues = new Integer[strValues.length];
		for(int index = 0; index < strValues.length; index++) {
			intValues[index] = Integer.parseInt(strValues[index]);
		}
		return intValues;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值