我在STS中有Roo生成的项目,并尝试自定义更新/删除方法以使用MongoDB(用于级联更新和删除)。我创建了更新(删除)父级时更新(删除)子级的服务方法:
public class NoteServiceImpl implements NoteService {
@Autowired
MongoTemplate mongoTemplate;
public void updateNotesWithNoteBook(Notebook notebook) {
Update update = new Update().set("notebook.name", notebook.getName())
.set("notebook.author", notebook.getAuthor());
Query query = Query.query(Criteria.where("notebook._id").is(
new ObjectId(notebook.getId().toString(16))));
mongoTemplate.updateMulti(query, update, Note.class);
}
...the similar for delete action
NoteService接口是Roo生成的,如下所示:
@RooService(domainTypes = { org.dp.mongo.shortnotes.domain.Note.class })
public interface NoteService {
}
我从父实体Notebook的Roo控制器* .aj到Notebook控制器类的更新和检测方法的推入重构,并添加了对子服务方法的调用:
@RequestMapping("/notebooks")
@Controller
@RooWebScaffold(path = "notebooks", formBackingObject = Notebook.class)
public class NotebookController {
@Autowired
private NoteService noteService;
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid Notebook notebook, BindingResult bindingResult,
Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, notebook);
return "notebooks/update";
}
uiModel.asMap().clear();
notebookService.updateNotebook(notebook);
**noteService.updateNotesWithNoteBook(notebook);**
return "redirect:/notebooks/"
+ encodeUrlPathSegment(notebook.getId().toString(),
httpServletRequest);
}
the similar for delete method...
最后得到错误,noteService没有方法updateNotesWithNoteBook和delete方法。如何修复它们?
答案 0 :(得分:0)
NoteService接口中是否存在updateNotesWithNoteBook方法?
你必须将它放在界面中,这就是你从控制器中调用的内容。