我无法从我的 Web 界面插入对象...
我有一个公式,然后单击确定,我启动了一个 java 函数......
我的 EndpointClass 具有以下自动生成的插入功能
@ApiMethod(name = "insertQuestion")
public Question insertQuestion(Question question)
{
EntityManager mgr = getEntityManager();
try
{
if (containsQuestion(question))
{
throw new EntityExistsException("Object already exists");
}
mgr.persist(question);
}
finally
{
mgr.close();
}
return question;
}
我有一个简单的问题类
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
private String question;
private String answerCorrect;
private String answerWrong1;
private String answerWrong2;
private String answerWrong3;
public Question(String question, String answerCorrect, String answerWrong1, String answerWrong2, String answerWrong3)
{
this.question = question;
this.answerCorrect = answerCorrect;
this.answerWrong1 = answerWrong1;
this.answerWrong2 = answerWrong2;
this.answerWrong3 = answerWrong3;
}
// + all the getters and setters...
我尝试从我的网页中添加如下内容:
var question = document.formQuestion.elements[0];
var answer = document.formQuestion.elements[1];
var answerWrong1 = document.formQuestion.elements[2];
var answerWrong2 = document.formQuestion.elements[3];
var answerWrong3 = document.formQuestion.elements[4];
var q2 = new Object();
q2.question = question;
q2.answerCorrect = answer;
q2.answerWrong1 = answerWrong1;
q2.answerWrong2 = answerWrong2;
q2.answerWrong3 = answerWrong3;
gapi.client.questionendpoint.insertQuestion({q2}).execute(handleMessageResponse);
//gapi.client.questionendpoint.insertQuestion(q2).execute(handleMessageResponse);
//gapi.client.questionendpoint.insertQuestion({"question": q2}).execute(handleMessageResponse);
但是那个(以及我尝试过的所有其他事情)都不起作用......
有人可以告诉我如何正确地做到这一点吗?