当前位置: 代码迷 >> J2EE >> spring mvc,该如何解决
  详细解决方案

spring mvc,该如何解决

热度:227   发布时间:2016-04-22 02:26:11.0
spring mvc
用到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());    }}
  相关解决方案