springmvc 能否通过代码获取到请求是post还是get?还有action配置的请求方式?
展开全部
spring 跟struts2一样,只要是参数跟javaben设置的一样,无论是post,还是get都能获取到参数。
//添加操作
@RequestMapping("/add")//跳转路径
public String addAccount(HttpServletRequest req) {
Account acc = new Account();
acc.setName(req.getParameter("name"));//获取表单参数方法
System.out.println(req.getParameter("pwd"));
acc.setPwd(req.getParameter("pwd"));
as.save(acc);
//as.addAccount(acc);
req.setAttribute("key", "success");
return "hzjw";//跳转路径
}
简化之后就是这样
@RequestMapping("/add")//跳转路径
public String addAccount(HttpServletRequest req, Account acc) {
as.save(acc);
//as.addAccount(acc);
req.setAttribute("key", "success");
return "hzjw";
}
//添加操作
@RequestMapping("/add")//跳转路径
public String addAccount(HttpServletRequest req) {
Account acc = new Account();
acc.setName(req.getParameter("name"));//获取表单参数方法
System.out.println(req.getParameter("pwd"));
acc.setPwd(req.getParameter("pwd"));
as.save(acc);
//as.addAccount(acc);
req.setAttribute("key", "success");
return "hzjw";//跳转路径
}
简化之后就是这样
@RequestMapping("/add")//跳转路径
public String addAccount(HttpServletRequest req, Account acc) {
as.save(acc);
//as.addAccount(acc);
req.setAttribute("key", "success");
return "hzjw";
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询