0
我目前正在開發一個帶有Play2的Web服務,並且我有一個操作組合問題。Action Compositon Play2 Java
這裏是我的Web服務提供的方法之一:
@Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Result createObject() {
try {
JsonNode json = request().body().asJson();
// Retrieve user from request
User user;
try {
user = getUserFromRequest();
}
catch (BeanNotFoundException e) {
return badRequest(Messages.get("userNotFound"));
}
// Retrieve owner from user
Owner owner;
try {
owner = getOwnerFromUser(user);
}
catch (BeanNotFoundException e) {
return badRequest(Messages.get("ownerNotFound"));
}
// Create the object
// Here is the code using User and Owner previously found
}
catch (BeanValidationException e) {
return badRequest(JsonUtils.beanValidationMessagesToJson(e));
}
}
的問題是,我要重複的代碼檢索用戶在我的web服務的每個方法的所有者。
我如何使用動作組合來做到這一點,因爲我在我的主要動作中調用方法? 我閱讀了文檔http://www.playframework.com/documentation/2.1.1/JavaActionsComposition,但我不明白如何用簡單的註釋來改變動作的行爲?
謝謝
感謝您的回答,但我不知道怎樣才能適應我的使用情況下,這個例子。 ..如何使用請求創建註釋? – c4k