springmvc框架中,在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型

来源:互联网 发布:科比场均数据每年 编辑:程序博客网 时间:2024/05/16 05:02

springmvc框架中,在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型

在UserAction中

/** *  控制器 * @author AdminTC */@Controller@RequestMapping(value="/user")public class UserAction {/** * 自定义类型转换器 */@InitBinderpublic void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),true));}/** * 用户注册,只能接收POST请求 */@RequestMapping(method=RequestMethod.POST,value="/register")public String registerMethod(User user,Model model) throws Exception{System.out.println("用户注册:" + user.toString());//将user绑定到model对象中model.addAttribute("user",user);//转发到success.jsp页面return "/jsp/success.jsp";}}

在spring.xml中

<!-- Action,让springioc容器去扫描带@Controller的类 --><context:component-scan base-package="cn.itcast.javaee.springmvc.app19"/>


阅读全文
0 0
原创粉丝点击