SpringMVC前端传值的问题总结

最近在忙着一个练习,前端的参数传到后台都变为null

百度了下,发现最终是因为用错一个注解导致,使用路径直接访问是通过@PathVariabl String id,看了一下使用注解获取路径中传递参数 ,共有以下几种情况:

路径中参数带有

@RequestMapping(value = "/{id}/{str}")

方法中是使用

@PathVariabl String id这种形式的注解

通过form表单使用POST方法传递一个对象
@RequestMapping(method = RequestMethod.POST) 
 public String processSubmit(@ModelAttribute("pojo") Pojo pojo)
直接从request中获取参数,原始方法
@RequestMapping(method = RequestMethod.GET) 
public get(HttpServletRequest request, HttpServletResponse response) { 
        System.out.println(request.getParameter("a")); 
   } 
用注解@RequestParam绑定请求参数a到变量a
 @RequestMapping(value = "/requestParam", method = RequestMethod.GET) 
   public String setupForm(@RequestParam("a") String a, ModelMap model) 

猜你喜欢

转载自blog.csdn.net/weixin_38120374/article/details/81176432