2
我有以下類:播放框架2.5的Json POST請求粘結劑
public class NoteForm {
public Integer id;
@Constraints.Required
public Integer userId;
@Constraints.Required
public String note;
// cant get any of the following to work
public Int[] tags;
public String[] tags;
public List<int> tags;
}
而且像這樣的控制器操作:
@BodyParser.Of(BodyParser.Json.class)
public Result updateNote(){
Form<NoteForm> noteForm = NOTE_FORM.bind(request().body().asJson());
//also have tried the following
//Form<NoteForm> noteForm = NOTE_FORM.bindFromRequest();
if(noteForm.hasErrors()){
return badRequest(noteForm.errorsAsJson());
}else{
noteService.saveNote(noteForm.get());
return jsonResult(ok(Json.toJson("Save Succeeded")));
}
}
當使用JSON我張貼的JSON從$阿賈克斯看起來像下面這樣的對象:
{
"id":"1",
"userId":"1",
"note":"adsfadsfdsaaf",
"tags":["5","6"]
}
我無法獲取表單的標籤屬性來綁定,我做錯了什麼?
我目前正在解決這個問題,只要使用下面的代碼,但我不能使用表單助手利用遊戲架構驗證:
NoteForm note = Json.fromJson(json, NoteForm.class);
奇怪。 '列出標籤;'也失敗? –
jsonmurphy
剛剛嘗試過,並沒有奏效。 – develop4fun2011
不要錯過getters和setter?你是否設置了Content-type:application/json頭文件? – Tijkijiki