How to save data and parse the process of saving date parameters in springmvc
This article mainly introduces "springmvc how to save the data and date parameter save process analysis", in daily operation, I believe many people in springmvc how to save the data and date parameter save process analysis problems have doubts, small make up consult all kinds of information, sort out simple and easy to use operation method, hope to answer "springmvc how to save the data and date parameter save process analysis" doubts helpful! Next, please follow the small series to learn together!
1. When a date-type parameter is passed in the Controller class
Date: @RequestMapping("todate.do") public String todate(Date date) { System.out.println(date); return "list"; } @InitBinder public void initBinder(ServletRequestDataBinder binder){ //As long as the data format sent from the webpage is y-MM-dd, it will be converted to Date type binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); }
2. When you want to pass multiple parameters
Name:
Password:
Gender:
Age:
Address:
Date of birth:
@RequestMapping("list2.do") public String list2(Users users ) { System.out.println(users); return "list"; } @InitBinder public void initBinder(ServletRequestDataBinder binder){ //As long as the data format from the webpage is y-MM-dd, it will be converted to Date type. binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); }
Controller Data preservation
Save to request
(1)ModelAndView
@RequestMapping("aaa.do") public ModelAndView index() { ModelAndView mv = new ModelAndView(); mv.setViewName("index"); mv.addObject("name","Zhang San"); return mv; }
(2)Model
@RequestMapping("aaa.do") public String index(Model model) { model.addAttribute("name", "Li Si"); 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"; }
Save to session
@RequestMapping("list.do") public String list(HttpSession session) { session.setAttribute("name","wang"); return "index2"; }
Save to application
@RequestMapping("list.do") public String list(HttpSession session) { session.getServletContext().setAttribute("name","wang"); return "index2"; } At this point, the study of "how to save data in springmvc and the analysis of the saving process of date parameters" is over. I hope you can solve your doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!