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

来源:互联网 发布:linux权限数值计算器 编辑:程序博客网 时间:2024/06/07 06:27
@Controller
@RequestMapping("/student")
public class StudentController {

    private static List<Student> studentList=new ArrayList<Student>();

    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;
    }
0 0
原创粉丝点击