In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the sample analysis of SpringMVC response view and result view. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. Return a string. Model transfers data / * returns String * @ param model * @ return * / @ RequestMapping ("/ testString") public String testString (Model model) {System.out.println ("testString method executes..."); / / simulates querying the User object User user = new User () from the database; user.setUsername ("Meimei") User.setPassword ("123"); user.setAge (30); / / model object model.addAttribute (" user ", user); return" success " 2. Void (used infrequently) / * is void * request to forward a request without writing the name of the project * / @ RequestMapping ("/ testVoid") public void testVoid (HttpServletRequest request, HttpServletResponse response) throws Exception {System.out.println ("testVoid method executed.") / / write a program for forwarding requests / / request.getRequestDispatcher ("/ WEB-INF/pages/success.jsp") .forward (request,response); / / redirect / / response.sendRedirect (request.getContextPath () + "/ index.jsp"); / / set Chinese garbled response.setCharacterEncoding ("UTF-8"); response.setContentType ("text/html;charset=UTF-8") / / will respond directly to response.getWriter (). Print ("Hello"); return;} 3, return to ModelAndView to complete the jump page and transfer data / * return ModelAndView * @ return * / @ RequestMapping ("/ testModelAndView") public ModelAndView testModelAndView () {/ / create ModelAndView object ModelAndView mv = new ModelAndView () System.out.println ("testModelAndView method executes..."); / / simulate querying User objects from the database User user = new User (); user.setUsername ("Xiao Feng"); user.setPassword ("456"); user.setAge (30) / / if the user object is stored in the mv object, the user object will also be stored in the request object mv.addObject ("user", user); / / which page mv.setViewName ("success") to jump to; return mv 4. Forward forwarding / * forwarding using keywords * @ return * / @ RequestMapping ("/ testForwardOrRedirect") public String testForwardOrRedirect () {System.out.println ("testForwardOrRedirect method executes..."); / / forwarding return "forward:/WEB-INF/pages/success.jsp" of the request } 5. Redirect redirect / * use keywords to redirect * @ return * / @ RequestMapping ("/ testForwardOrRedirect") public String testForwardOrRedirect () {System.out.println ("testForwardOrRedirect method executes..."); / / redirect return "redirect:/index.jsp" } this is the end of the article on "sample Analysis of SpringMVC response View and result View". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.