-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebUtils.java
More file actions
47 lines (40 loc) · 1.18 KB
/
WebUtils.java
File metadata and controls
47 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.atguigu.utils;
import com.atguigu.pojo.User;
import org.apache.commons.beanutils.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
public class WebUtils {
/**
* 把Map中的值注入到对应的 JavaBean属性中
* @param value
* @param bean
*/
public static <T> T copyParamTOBean(Map value, T bean){
try {
System.out.println("注入之前"+ bean);
/**
* 把所有请求参数都注入到user对象中
*/
BeanUtils.populate(bean,value);
System.out.println("注入之后"+ bean);
} catch (Exception e) {
e.printStackTrace();
}
return bean;
}
/**
* 将字符串转为int类型
*
* @param strInt 接收传来的 字符串
* @param defaultValue 默认值 (int)
* @return 转成功就是 返回转换后的int值 ,失败 则返回 默认值
*/
public static int parseInt(String strInt,int defaultValue){
try {
return Integer.parseInt(strInt);
} catch (Exception e) {
//e.printStackTrace();
}
return defaultValue;
}
}