ajax通过post方式传参给后台controller,怎么获取传过来的参数
答案:1 悬赏:30 手机版
解决时间 2021-02-27 19:02
- 提问者网友:我一贱你就笑
- 2021-02-27 06:15
ajax通过post方式传参给后台controller,怎么获取传过来的参数
最佳答案
- 五星知识达人网友:西风乍起
- 2021-02-27 07:22
方式比较多:
@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();
}
@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();
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯