Spring getting error in get attribute method
I want setting the attribute in first modelandview method with the help of bean and trying to get the attributes in other modelandview method in same controller but getting null value my code is below
@RequestMapping(value="/insert",method=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");
}
From the first look to your code , I notice that your request method not specified. At this case (When using @ModelAttribute) you have to make it as (POST) request.
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@RequestMapping(value = "/accinsert" , method = RequestMethod.POST)
Why ? because actually your object will be retrieved due to Form Submission which is treated as POST request. Try that thing and check the results. If the problem is still maybe you have some real problem in your Presentation Layer (eg JSP Page) that is responsible about submitting the data.
Good Luck !
链接地址: http://www.djcxy.com/p/68080.html上一篇: Spring测试服务自动装配导致null
下一篇: Spring获取属性方法时出错