用到spring mvc + hibernate 开发,遇到一个删除操作时,让他重定向到一个显示列表的页面,出现错误。
java.lang.IllegalArgumentException: attempt to create delete event with null entity
在controller 里面 写的
@RequestMapping("delete/{id}")
public String delete(User user,@PathVariable String id){
User user1 = this.baseDao.get(User.class, id);
System.out.println(id);
this.baseDao.delete(user1);
return "redirect:success"; }
是不是上面红色重定向出了问题,解决方法附上,谢谢
------解决方案--------------------
嗯。 确实写错了。 以跳转到CSDN首页为例。
return "redirect:http://www.csdn.net";
redirect:以后也可以跟相对地址但不是逻辑视图名称
如
return "redirect:xxx.do?param1=value1"; // 带参数的请求
------解决方案--------------------
- Java code
@Controllerpublic class ContactController { @RequestMapping(value = "/addContact", method = RequestMethod.POST) public String addContact(@ModelAttribute("contact") Contact contact, BindingResult result) { // @ModelAttribute will binds the data from request to the object // Contact. System.out.printf("Name: %s, Mail: %s\n", contact.getName(), contact.getMail()); return "redirect:contacts.htm"; // 看这里 } @RequestMapping("/contacts") public ModelAndView showContacts() { return new ModelAndView("contact", "command", new Contact()); }}