Background data back to the front desk three ways bindings (Model, Map.ModelAndView)

@ Embodiment 1: Binding Data model by 
    @RequestMapping (value = "findByIdModel", Method = RequestMethod.GET)
     public String findByIdModel (@RequestParam ( "EMPNO") int ID, the Model model) { 
        
        Emp EMP = empService.findById (ID); // from the service layer data returned 
        
        model.addAttribute ( "EMP", EMP); // bind data 
        
        return "findById"; // page returned 
    }
 // mode 2: the Map 
    @RequestMapping (value = "findByIdMap", Method = RequestMethod.GET)
     public String findByIdMap (@RequestParam ( "EMPNO") int ID, the Map <String,Object> map) {
        
        Emp emp = empService.findById(id);
        
        map.put("emp", emp);
        
        return "findbyid";
    }
    
    //方式3:通过ModelAndView
    @RequestMapping(value = "findByIdMAV", method = RequestMethod.GET)
    public ModelAndView findByIdMAV(@RequestParam("empno") int id) {
        
        Emp emp = empService.findById(id);
        
//        ModelAndView mav = new ModelAndView("findbyid");
        ModelAndView mav = new ModelAndView();
        
        mav.setViewName("findbyid");Set Back Page//
        
        mav.addObject ( "EMP", EMP); // set the value of the action passed 
        
        System.out.println ( "use ModelAndView:" + EMP); 
        
        return MAV; 
    }

 

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/11324380.html