1. 程式人生 > >SpringMVC接受前端參數的幾中方式

SpringMVC接受前端參數的幾中方式

寫入 springmvc log dex pre mode lmap java clas

1.直接將表單中的數據寫入形參中

@RequestMapping
public String showIndex(String name,String pass){
    System.Out.Println("name:"+name);
    System.Out.Println("pass:"+pass);
}

2.使用HttpServletRequest

@RequestMapping("/")
public String showIndex(HttpServletRequest req) {
    String name = req,getParmeter("name");
    String pass 
= req.getParmeter("pass"); }

3.使用和保單數據一樣的javaBean

class ModelMap{
    private String name;
    private String pass;



}
@RequestMapping("/")
public String showIndex(ModelMap model) {
        syso(model.name);
        syso(model.pass);
    }

  

SpringMVC接受前端參數的幾中方式