/**
* 从<code>HttpServletRequest</code>中获取<code>String</code>类型的值, 不允许传递空串
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
String getString(HttpServletRequest request,String paramName){
return
getString(request, paramName,
false
);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>String</code>类型的值
*
* 如果传递过来的参数为包含空白字符串的字符,认为为有效值, 否则返回null
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
String getString(HttpServletRequest request,String paramName,
boolean
isWithSpace) {
String tmp = request.getParameter(paramName);
if
(isWithSpace){
if
(!StringUtils.isEmpty(tmp)){
return
tmp;
}
}
else
{
if
(!StringUtils.isBlank(tmp)){
return
tmp;
}
}
return
null
;
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Long</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
Long getLong(HttpServletRequest request,String paramName) {
return
getLong(request, paramName, -1L);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Long</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @param defaultValue
* 默认值
* @return
* 返回需要的值
*/
public
static
final
Long getLong(HttpServletRequest request,String paramName,Long defaultValue) {
String tmp = request.getParameter(paramName);
if
(!StringUtils.isBlank(tmp)){
try
{
Long value = Long.parseLong(tmp);
return
value;
}
catch
(NumberFormatException e) {
return
-1L;
}
}
return
defaultValue;
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Integer</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
Integer getInt(HttpServletRequest request,String paramName) {
return
getInt(request,paramName, -
1
);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Integer</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @param defaultValue
* 默认值
* @return
* 返回需要的值
*/
public
static
final
Integer getInt(HttpServletRequest request,String paramName,
int
defaultValue) {
String tmp = request.getParameter(paramName);
if
(!StringUtils.isBlank(tmp)){
try
{
Integer value = Integer.parseInt(tmp);
return
value;
}
catch
(NumberFormatException e) {
return
-
1
;
}
}
return
defaultValue;
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Short</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
Short getShort(HttpServletRequest request,String paramName) {
return
getShort(request,paramName, (
short
)-
1
);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Short</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @param defaultValue
* 默认值
* @return
* 返回需要的值
*/
public
static
final
Short getShort(HttpServletRequest request,String paramName,
short
defaultValue) {
String tmp = request.getParameter(paramName);
if
(!StringUtils.isBlank(tmp)){
try
{
Short value = Short.parseShort(tmp);
return
value;
}
catch
(NumberFormatException e) {
return
(
short
)-
1
;
}
}
return
defaultValue;
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Byte</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
Byte getByte(HttpServletRequest request,String paramName) {
return
getByte(request,paramName, (
byte
)-
1
);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Byte</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @param defaultValue
* 默认值
* @return
* 返回需要的值
*/
public
static
final
Byte getByte(HttpServletRequest request,String paramName, Byte defaultValue) {
String tmp = request.getParameter(paramName);
if
(!StringUtils.isBlank(tmp)){
try
{
Byte value = Byte.parseByte(tmp);
return
value;
}
catch
(NumberFormatException e) {
return
(
byte
)-
1
;
}
}
return
defaultValue;
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Double</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
Double getDouble(HttpServletRequest request,String paramName) {
return
getDouble(request, paramName,-1D);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Double</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @param defaultValue
* 默认值
* @return
* 返回需要的值
*/
public
static
final
Double getDouble(HttpServletRequest request,String paramName, Double defaultValue) {
String tmp = request.getParameter(paramName);
if
(!StringUtils.isBlank(tmp)){
try
{
Double value = Double.parseDouble(tmp);
return
value;
}
catch
(NumberFormatException e) {
return
-1D;
}
}
return
defaultValue;
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Float</code>类型的值
*
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @return
* 返回需要的值
*/
public
static
final
Float getFloat(HttpServletRequest request,String paramName) {
return
getFloat(request, paramName,-1F);
}
/**
* 从<code>HttpServletRequest</code>中获取<code>Float</code>类型的值
*
* @param request
* @see HttpServletRequest
* @param paramName
* 参数名称
* @param defaultValue
* 默认值
* @return
* 返回需要的值
*/
public
static
final
Float getFloat(HttpServletRequest request,String paramName, Float defaultValue) {
String tmp = request.getParameter(paramName);
if
(!StringUtils.isBlank(tmp)){
try
{
Float value = Float.parseFloat(tmp);
return
value;
}
catch
(NumberFormatException e) {
return
-1F;
}
}
return
defaultValue;
}