Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to save data and parse the process of saving date parameters in springmvc

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report