1、提交数据的处理(1)提交的域名称和处理方法的参数一致即可提交的数据:处理方法:@RequestMapping("/hello")publicStringhello(Stringname){System.out.println("name..."+name);return"index.jsp";}结果:(2)提交的域名称和参数名不一致提交的数据:处理方法:@RequestMapping("/hello")publicStringhello(@RequestParam("uname")Stringname){System.out.println("name..."+name);return"index.jsp";}结果:(3)提交的是一个对象,要求提交的表单域名和对象的属性名一致,参数使用对象作为参数即可提交的数据:处理方法:@RequestMapping("/user")publicStringuser(Useruser){System.out.println(user);return"index.jsp";}}结果:实体类:publicclassUser{privateintid;privateStringname;privateStringpwd;get,set…@OverridepublicStringtoString(){return"User[id="+id+",name="+name+",pwd="+pwd+"]";}}2、将数据显示到UI层(1)通过ModelAndView---需要通过视图解析器@RequestMapping("/hello")publicModelAndViewhello(HttpServletRequestrequest,HttpServletResponseresponse){//相当于request.setAtttibute("msg","SpringMVCannotation");ModelAndViewmv=newModelAndView();mv.addObject("msg","SpringMVCannotation");mv.setViewName("hello");returnmv;}(2)通过ModelMap---不需要通过视图解析器ModelMap需要作为处理方法的参数提交的数据:处理方法:@RequestMapping("/hello1")publicStringhello1(Stringname,ModelMapmodel){System.out.println("name..."+name);//相当于request.setAtttibute("name",name);model.addObject("name",name);return"index.jsp";}结果:ModelAndView和ModelMap的区别:相同点:都可以将数据封装显示到表示层页面中不同点:1、ModelAndView可以指定跳转的视图,而ModelMap不能2、ModelAndView需要视图解析器,ModelMap不需要配置