讲解一下RequestMapping,Request请求参数和ModelAndView返回模型和视图

@Controller
@RequestMapping("/student")
public class StudentController {

    private static List studentList=new ArrayList();

    static{
        studentList.add(new Student(1,"ÕÅÈý",11));
        studentList.add(new Student(2,"ÀîËÄ",12));
        studentList.add(new Student(3,"ÍõÎå",13));
    }

    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView mav=new ModelAndView();
        mav.addObject("studentList", studentList);
        mav.setViewName("student/list");
        return mav;
    }

    @RequestMapping("/preSave")
    public ModelAndView preSave(@RequestParam(value="id",required=false) String id){
        ModelAndView mav=new ModelAndView();
        if(id!=null){
            mav.addObject("student", studentList.get(Integer.parseInt(id)-1));
            mav.setViewName("student/update");
        }else{
            mav.setViewName("student/add");           
        }
        return mav;
    }

你可能感兴趣的:(spring,mvc)