0
如何在Google Sitebricks中編輯實體是正確的方法。現在我是這樣做的。如何在Google Sitebricks中編輯實體
@Show("/WEB-INF/templates/adm/editentry.html")
@Decorated
@At("/adm/entry/:id")
public class EditEntry extends AdminLayout {
@Inject
private EntryService entryService;
private Entry entry = new Entry();
public Entry getEntry() {
return entry;
}
public void setEntry(Entry entry) {
this.entry = entry;
}
@Get
public void getForm(@Named("id") String id) {
this.entry = entryService.get(id);
}
@Post
public String save() {
Entry exist = entryService.get(entry.getId());
if (exist == null) {
FlashMap.setErrorMessage("No entry found with id:" + entry.getId());
} else {
if (StringUtils.isBlank(entry.getExcerpt())) {
entry.setExcerpt(entry.getContent());
}
entry.setBlog(exist.getBlog());
entry.setType(exist.getType());
entry.setStatus(exist.getStatus());
entry.setAuthor(exist.getAuthor());
entryService.saveOrUpdate(entry);
}
return request.getContextPath() + "/adm/entries";
}
}
在POST方法我加載從數據庫中存在條目,則設置不修改的字段返回到從形式結合的條目。然後對數據庫進行更新。
這是在sitebrciks中正確的方式嗎?有沒有一種方法可以像保存方法一樣在保存方法中進行更新輸入。謝謝。
你好。我不明白這個問題。 「就像入口創建方式一樣,在保存方法中更新條目」意味着什麼? – Thomas