我會繼續爲我的新手做的。
第一步:從我的袋鼠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