0

我正在关注 MobileFirst Platform 7 的Java SQL 适配器教程。我尝试使用 REST 调用类型创建新用户@POST,但 chrome 控制台是

发布 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
);}
4

1 回答 1

4

POST由于您正在向您不应该使用的适配器发送请求,setQueryParameter因为它是为GET请求而设计的,因此您应该使用sendFormParameters而不是send. 您更新的代码应如下所示:

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);
}
于 2015-04-16T21:20:10.977 回答