request封装到Bean对象
public static <T> T request2Bean(HttpServletRequest httpServletRequest, Class<T> aClass) {
try {
ConvertUtils.register(new DateLocaleConverter(), Date.class);
T bean = aClass.newInstance();
httpServletRequest.setCharacterEncoding("UTF-8");
Enumeration enumeration = httpServletRequest.getParameterNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = httpServletRequest.getParameter(name);
if (!value.equals("") && value != null) {
BeanUtils.setProperty(bean, name, value);
}
}
return bean;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("封装数据到Bean中,失败了!");
}
}
UUID工具方法
public static String makeId() {
return UUID.randomUUID().toString();
}