我会继续为我的新手做的。
第一步:从我的袋鼠CONTROLER切我的方法(EntityController_Roo_Controller.aj)
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid Got got, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("got", got);
addDateTimeFormatPatterns(uiModel);
return "gots/create";
}
uiModel.asMap().clear();
got.persist();
return "redirect:/gots/" + encodeUrlPathSegment(got.getId().toString(), httpServletRequest);
}
第二步:梅索德粘贴到Java位指示(EntityController.java)
第三步:编辑获取usernmae的方法并修改我的方法
- 加入主要主要作为 参数
更新我的实体: got.setUserkt(principal.getName());
@RequestMapping(方法= RequestMethod.POST)
public String create(@Valid Got got, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest, Principal principal) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("got", got);
addDateTimeFormatPatterns(uiModel);
return "gots/create";
}
uiModel.asMap().clear();
got.setUserkt(principal.getName());
got.persist();
return "redirect:/gots/" + encodeUrlPathSegment(got.getId().toString(), httpServletRequest);
}
再次
谢谢!
这是个好主意。我可以看到你擅长春天...... – gpasse 2011-05-16 15:31:57
告诉我,我可以找到一个关于这种方法的好教程吗? – gpasse 2011-05-16 15:43:27
我找不到教程,但我发现[此链接](http://forum.springsource.org/showthread.php?100109-can-i-override-the-method()-in-controller-OR-域)。因此,只需在目标控制器的ITD中选择目标方法(文件名为'XxxController_Roo_Controller.aj')并为其执行'Push In'重构(应该在Eclipse中可用)。然后打开你的'XxxController.java'并在保存之前执行你的实体修改(如你的代码片段)。请记住,您应该在Roo控制台运行时执行此操作。关于我的第一个建议(创建方面)只是读了一些关于AspectJ的内容。 – Constantiner 2011-05-16 15:51:14