zoukankan      html  css  js  c++  java
  • 关系管理系统:WebUtils工具类代码

    package cn.itcast.utils;
    
    import java.util.Date;
    import java.util.Enumeration;
    import java.util.UUID;
    
    import javax.servlet.http.HttpServletRequest;
    
    import org.apache.commons.beanutils.BeanUtils;
    import org.apache.commons.beanutils.ConvertUtils;
    import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;
    
    public class WebUtils {
        
        //把request中的数据封装到bean中
        public static <T> T request2Bean(HttpServletRequest request,Class<T> clazz){
            
            try{
                T t = clazz.newInstance();
                
                ConvertUtils.register(new DateLocaleConverter(), Date.class);
                Enumeration e = request.getParameterNames();
                while(e.hasMoreElements()){
                    String name = (String) e.nextElement();
                    String value = request.getParameter(name);
                    
                    BeanUtils.setProperty(t, name, value);
                }
                return t;
            }catch (Exception e) {
                throw new RuntimeException(e);
            }
            
        }
        
        
        public static String makeId(){//产生UUID
            return UUID.randomUUID().toString();
        }
    }
  • 相关阅读:
    [BZOJ3172]单词
    [BZOJ2434]阿狸的打字机
    [BZOJ1195]最短母串
    [codeforces743E]Vladik and cards
    [BZOJ2553]禁忌
    [BZOJ1009]GT考试
    [BZOJ3507]通配符匹配
    [BZOJ4027]兔子与樱花
    test20190308
    Luogu P2742 模板-二维凸包
  • 原文地址:https://www.cnblogs.com/lichone2010/p/3175891.html
Copyright © 2011-2022 走看看