springmvc中进行数据保存以及日期参数的保存过程解析

这篇文章主要介绍了springmvc中进行数据保存以及日期参数的保存过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1.在Controller类中接受传入的日期类型的参数时

 
日期:

 @RequestMapping("todate.do") public String todate(Date date) { System.out.println(date); return "list"; } @InitBinder public void initBinder(ServletRequestDataBinder binder){ //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); }

2.当要传入多个参数时

 
姓名:
密码:
性别:
年龄:
地址:
生日:
 @RequestMapping("list2.do") public String list2(Users users ) { System.out.println(users); return "list"; } @InitBinder public void initBinder(ServletRequestDataBinder binder){ //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); }

Controller数据保存

保存至request里

(1)ModelAndView

 @RequestMapping("aaa.do") public ModelAndView index() { ModelAndView mv = new ModelAndView(); mv.setViewName("index"); mv.addObject("name","张三"); return mv; }

(2)Model

 @RequestMapping("aaa.do") public String index(Model model) { model.addAttribute("name", "李四"); return "index"; }

(3)map

 @RequestMapping("aaa.do") public String index(Map map) { map.put("name", "222"); return "index"; }

(4)request

 @RequestMapping("list.do") public String list(HttpServletRequest request) { request.setAttribute("name","wang"); return "index2"; }

保存至session里

 @RequestMapping("list.do") public String list(HttpSession session) { session.setAttribute("name","wang"); return "index2"; }

保存至application里

 @RequestMapping("list.do") public String list(HttpSession session) { session.getServletContext().setAttribute("name","wang"); return "index2"; }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持html中文网。

以上就是springmvc中进行数据保存以及日期参数的保存过程解析的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java