@RequestParam注解来映射请求参数 /** * @RequestParam来映射请求参数 * value值即为请求参数参数名 * required表示该参数是否必须,默认为true必须 * defaultValue表示该请求参数的默认值 */@RequestMa
/** * @RequestParam来映射请求参数 * value值即为请求参数参数名 * required表示该参数是否必须,默认为true必须 * defaultValue表示该请求参数的默认值 */ @RequestMapping("/testRequestParam") public String testRequestParam(@RequestParam(value="username")String name, @RequestParam(value="pwd")String pwd, @RequestParam(value="age", required=false, defaultValue="0")int age) { System.out.println("username="+name); System.out.println("pwd="+pwd); System.out.println("age="+age); return success; }ModelAndView
/* * 目标方法的返回值可以是ModelAndView类型 * 其中可以包含视图和模型信息 * SpringMVC会将ModelAndView的model中数据放入request域中 */ @RequestMapping("/testModelAndView") public ModelAndView testModelAndView() { String viewName=success; ModelAndView modelAndView=new ModelAndView(viewName); User user1=new User("zsl","123","aa@163.com",12,new Address("Beijing","Beijing")); User user2=new User("wc","123","bb@163.com",21,new Address("Jiangxi","LePing")); Listlist=new ArrayList<>(); list.add(user1); list.add(user2); modelAndView.addObject("studentMsg",list); return modelAndView; }