SpringMVC 参数传递见解5

5.参数传递

5.1.ModelAndView传递

  • 编写controller

    @Controller
    @RequestMapping("/account")
    public class AccountController {
    
        //也可以不创建ModelAndView,直接在参数中指定
        @RequestMapping(value = "/findAccount9")
        public ModelAndView findAccount9(ModelAndView mv) {
            mv.addObject("msg", "欢迎你 springmvc");
            mv.setViewName("success");
            return mv;
        }
    }
    
  • 在index.jsp里面定义超链接

    <a href="/account/findAccount9">ModelAndView参数传递a>
    

5.2.Model传递

  • 编写controller

    @Controller
    @RequestMapping("/account")
    public class AccountController {
    
        @RequestMapping(value = "/findAccount10")
        public String findAccount10(Model model) {
            model.addAttribute("msg", "欢迎你 springmvc");
            return "success";
        }
    }
    
  • 在index.jsp里面定义超链接

    <a href="/account/findAccount10">Model参数传递a>
    

5.3.ServletAPI传递

  • 编写controller

    @Controller
    @RequestMapping("/account")
    public class AccountController {
    
        @RequestMapping("/findAccount11")
        public String findAccount11(HttpServletRequest request, 
                                    HttpServletResponse response){
            request.setAttribute("msg","欢迎你 springmvc");
            return "success";
        }
    }
    
  • 在index.jsp里面定义超链接

    <a href="/account/findAccount11">ServletAPI传递a>
    

你可能感兴趣的:(开发语言,spring,mvc)