zoukankan      html  css  js  c++  java
  • BeanUtils 日期转换(本地格式yyyy-MM-dd)转换成date

    1.BeanUtils工具的使用

    1)beanUtils 可以便于对javaBean的属性进行赋值。

    2)beanUtils 可以便于对javaBean的对象进行赋值。

    3)beanUtils可以将一个MAP集合的数据拷贝到一个javabean对象中。

    BeanUtils具体使用:https://www.cnblogs.com/vmax-tam/p/4159985.html

    2.BeanUtils 从web获取表单(包括日期)

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            request.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
            //获取表单数据
            User user =new User();
            try {
                /*ConvertUtils.register(new Converter() {
                    @Override
                    public Object convert(Class type, Object value) {//注册一个日期转换器
                        Date date1 = null;
                        if (value instanceof String){
                            String date = (String) value;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            try {
                                date1 = sdf.parse(date);
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                        }
                        return date1;
                    }
                },Date.class);*/
    
                //日期格式转换器yyyy-MM-dd转换成data类型
                ConvertUtils.register(new DateLocaleConverter(),Date.class);//yyyy-MM-dd转换成data类型
                //把一个map集合中的数据(表单数据)拷贝到javaBean中(user)
                BeanUtils.populate(user,request.getParameterMap());
    
                //调用业务逻辑
                UserService us = new UserServiceImpl();
                us.register(user);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //分发转向
            response.getWriter().write("注册成功!1秒钟跳转到主页");
            response.setHeader("refresh","1;url="+request.getContextPath()+"/index.jsp");
        }
  • 相关阅读:
    关于断电即关闭的电路设计
    Python-29_常用模块复习
    Python-28_组合_继承_多态_封装_反射
    Python-27_面向对象
    Python-26_模块-02_python内置模板
    Python-25_模块-01_调用基本操作、路径
    Python-24_综合练习-01_函数_文件处理_解耦--查询功能
    Python-23_装饰器-04_练习---无参装饰器、有参装饰器
    Python-22_装饰器-03_解压序列
    Python-21_装饰器-02_装饰器实现
  • 原文地址:https://www.cnblogs.com/mensan/p/10231999.html
Copyright © 2011-2022 走看看