ajax通过post方式传参给后台controller,怎么获取传过来的参数

2025-04-07 04:36:32
推荐回答(1个)
回答1:

方式比较多:

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView insert(HttpServletRequest request) {
        String name = request.getParameter("name");
        return new ModelAndView(); 
    }
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView insert(String name) {
        System.out.println(name);
        return new ModelAndView(); 
    }
public class User{
    private String name;
    private int age;
    //省略 get set
}

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView insert(User user) {
        System.out.println(user.getName());
        return new ModelAndView(); 
    }