四 SpringMVC与页面之间的参数传递

根据id查询商品信息

1 原生方式:使用Servlet  API  , request.getParameter("id");

2 直接将请求参数作为Controller中的形参:

public String itemEdit(Model model , Integer id),要求形参名和对应表单标签的name属性相同

3 使用@RequestParam获取参数:

public String itemEdit(Model model ,@RequestParam(value="id",required=true)  Integer ids) , value中的name必须与表单中的name相同

4 使用pojo对象绑定请求参数值,利用反射机制,找到User对象中的属性。要求表单name数对象属性名称相同

public String updateItem(Item item , Model model)

猜你喜欢

转载自www.cnblogs.com/ltfxy/p/10431280.html