zoukankan      html  css  js  c++  java
  • 在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型

    1)  在默认情况下,springmvc不能将String类型转成java.util.Date类型,所有我们只能在Action

    中自定义类型转换器

    <form action="${pageContext.request.contextPath}/user/add.action" method="POST">
            编号:<input type="text" name="id" value="${id}"/><br/>
            姓名:<input type="text" name="name" value="${name}"/><br/>
            薪水:<input type="text" name="sal" value="${sal}"/><br/>
            入职时间:<input type="text" name="hiredate" value='<fmt:formatDate value="${hiredate}" type="date"/>'/><br/>
            <input type="submit" value="注册"/>
        </form>
    @Controller
    @RequestMapping(value = "/user")
    public class UserAction {
        @InitBinder
        protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
            binder.registerCustomEditor(
                    Date.class, 
                    new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
        }
        @RequestMapping(value = "/add", method = RequestMethod.POST)
        public String add(int id, String name, double sal, Date hiredate,
                Model model) throws Exception {
            System.out.println("HelloAction::add()::POST");
            model.addAttribute("id", id);
            model.addAttribute("name", name);
            model.addAttribute("sal", sal);
            model.addAttribute("hiredate", hiredate);
            return "/register.jsp";
        }
    }
  • 相关阅读:
    手机如何当电脑的摄像头使用
    内网穿透软件
    如何在laravel框架中使用阿里云的oss
    css position 定位详解
    laravel 速查表
    window10如何查看连接过的wifi密码
    sweetalert弹出层组件
    phpstudy安装 与phpstudy_Windows web面板安装
    程序员修炼之道读后感
    JAVA-WEB-简单的四则运算
  • 原文地址:https://www.cnblogs.com/loaderman/p/10063300.html
Copyright © 2011-2022 走看看