0

我无法从我的 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);

但是那个(以及我尝试过的所有其他事情)都不起作用......

有人可以告诉我如何正确地做到这一点吗?

4

1 回答 1

1

对象“q2”周围不应有大括号。您在哪里添加对象 q2 的答案?q2 必须具有与您期望在端点中的对象相同的属性。还; 是否导入了Javascript客户端库,否则gapi将无法工作。您是否还尝试通过 https://.appspot.com/_ah/api/discovery/v1/apis 发现 API,这将提供其余端点的 url。另一个非常好的工具是 api explorer,您可以针对 localhost(调试)和部署的版本使用它:https ://developers.google.com/apis-explorer/?base=https://your_base_url/_ah/ api#p/

希望这可以帮助

于 2013-05-27T17:50:10.073 回答