Spring获取属性方法时出错
我想在bean的帮助下在第一个modelandview方法中设置属性,并尝试在同一控制器中获取其他modelandview方法中的属性,但获取空值,我的代码在下面
@RequestMapping(值= “/插入”,方法= RequestMethod.POST)
public ModelAndView inserData(@ModelAttribute SavingBeansavingBean,HttpServletRequestrs,Model m) {
System.out.println(savingBean.getFirstName());
if (savingBean != null)
System.out.println("abho");
SavingBean saving = persionalService.insertData(savingBean);
custid = saving.getCustomerId();
System.out.println(custid);
m.addAttribute("customId",saving);
System.out.println(saving.getDisgnProf());
List<SavingBean> list = new ArrayList<SavingBean>();
list.add(saving);
return new ModelAndView("AccountInfo","list", list);
} @RequestMapping(value =“/ accinsert”,method = RequestMethod.POST)public ModelAndView inserData(@ModelAttribute AccountBean accbean,HttpServletRequest rs,Model m){
SavingBean b = new SavingBean();
System.out.println("saas" + b.getCustomerId());
session = rs.getSession();
System.out.println("xxx" + rs.getAttribute("customId"));
accbean.setCustid((Long) rs.getAttribute("customId"));
AccountBean accbean1 = persionalService.insertacc(accbean);
return new ModelAndView("welcome");
}
从第一次看你的代码,我注意到你的请求方法没有指定。 在这种情况下(使用@ModelAttribute时)必须将其作为(POST)请求。
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@RequestMapping(value = "/accinsert" , method = RequestMethod.POST)
为什么? 因为实际上你的对象将被检索,因为表单提交被视为POST请求。 尝试一下并检查结果。 如果问题仍然存在,那么您的表示层(例如JSP页面)中有一些真正的问题负责提交数据。
祝你好运 !
链接地址: http://www.djcxy.com/p/68079.html上一篇: Spring getting error in get attribute method
下一篇: Spring MVC PRG pattern with multiple tabs session workaround