modelAndView 和RequestParam初识

来源:互联网 发布:巨大物体恐惧症 知乎 编辑:程序博客网 时间:2024/06/16 16:14
@Controller@RequestMapping("/student")public class StudentController {    public static List<Student> studentList=new ArrayList<Student>();    static{        studentList.add(new Student(1, "cai", "123"));        studentList.add(new Student(2, "cai1", "123"));        studentList.add(new Student(3, "cai2", "123"));    }    @RequestMapping("/login")    public ModelAndView login(@RequestParam(value="username" )String username, @RequestParam(value="password")  String password){        ModelAndView mav=new ModelAndView();        for (int i = 0; i < studentList.size(); i++) {            if(studentList.get(i).getUsername().equals(username)&&studentList.get(i).getPassword().equals(password)){                mav.setViewName("success");                System.out.println("zhaodao");                return mav;            }        }            mav.setViewName("error");            mav.addObject("msg","error msg");        return mav;            }    
@RequestParam(value="username" )  接收参数 
ModelAndView 设置视图和参数等

原创粉丝点击