MobileFirst 7.0 - 使用REST API调用示例Java SQL Adapter失败

时间:2015-04-16 18:00:25

标签: ibm-mobilefirst mobilefirst-adapters

我正在关注MobileFirst Platform 7的Java SQL Adapter教程。 我试图使用REST调用类型@POST创建一个新用户,但Chrome控制台是

  

POST http://192.168.56.1:10080/JavaAdapters/adapters/UserAdapter/?userId=test&lastName=test&firstName=test&password=test 409(冲突)

,回复是

  

列' userId'不能为空

我认为此过程的参数设置为空值

这是我的代码

var userId = "test";var lastName = "test";var firstName = "test";var password = "test";

function createUser(userId,lastName,firstName,password){
  busyIndicator.show();
  var resourceRequest = new WLResourceRequest("/adapters/UserAdapter/", WLResourceRequest.POST);
  resourceRequest.setQueryParameter("userId", userId);
  resourceRequest.setQueryParameter("lastName", lastName);
  resourceRequest.setQueryParameter("firstName", firstName);
  resourceRequest.setQueryParameter("password", password);
  resourceRequest.send().then(
        createUserSuccess,
        createUserFailure
);}

1 个答案:

答案 0 :(得分:4)

由于您要向适配器发送POST请求,因此您不应该使用setQueryParameter,因为它是专为GET个请求而设计的,您应该使用sendFormParameters代替send {1}}。您更新的代码应如下所示:

function createUser(userId, lastName, firstName, password){
  busyIndicator.show();
  var resourceRequest = new WLResourceRequest("/adapters/UserAdapter/", WLResourceRequest.POST);
  var user = {
    "userId": userId,
    "firstName": firstName,
    "lastName": lastName,
    "password": password
  };

  resourceRequest.sendFormParameters(user).then(createUserSuccess).fail(createUserFailure);
}