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の正しい方法ですか?エントリの作成方法と同じように、save メソッドでエントリを更新する方法はありますか。ありがとう。