MobileFirst - 调用 Java SQL Adapter 适配器过程
MobileFirst - Invoking Java SQL Adapter adapter procedure
我正在学习 MobileFirst Platform 7 的 Java SQL Adapter 教程。
我正在尝试使用 userId = "bjones" 获取用户,但我不知道如何将参数 {userId}
设置到过程 /adapters/UserAdapter/{userId}
.
function loadUsers(){
busyIndicator.show();
var resourceRequest = new WLResourceRequest("/adapters/UserAdapter/", WLResourceRequest.GET);
resourceRequest.setQueryParameter("userId", "bjones");
resourceRequest.send().then(
loadUsersSuccess,
loadUsersFailure
);}
function loadUsersSuccess(result){
WL.Logger.debug("Feed retrieve success");
busyIndicator.hide();
WL.Logger.debug(JSON.stringify(result));
if (result.responseJSON.length>0)
displayFeeds(result.responseJSON);
else
loadUsersFailure();}
function loadUsersFailure(result){
WL.Logger.error("Feed retrieve failure");
busyIndicator.hide();
WL.SimpleDialog.show("Banking Application", "Service not available. Try again later.",
[{
text : 'Reload',
handler : WL.Client.reloadApp
},
{
text: 'Close',
handler : function() {}
}]
);}
我的要求是
localhost:10080/JavaAdapters/adapters/UserAdapter/?userId=bjones
但 JSON 响应包含存储在我的数据库中的所有用户
Image for response
此外,REST 调用类型 @PUT
,路径参数 "userId" 和正文参数:"firstName","lastName","password",怎么样?为了更新用户
根据教程,适配器端点是 /{userId}
,这意味着 userId
不是查询参数,但它是 url 的一部分。您需要更新 loadUsers
函数,以便它在 url 的末尾附加 userId
,因此在您的示例中,完整路径将为 /adapters/UserAdapter/bjones
function loadUsers(){
busyIndicator.show();
var usedId = "bjones";
var resourceRequest = new WLResourceRequest("/adapters/UserAdapter/"+userId, WLResourceRequest.GET);
resourceRequest.send().then(loadUsersSuccess,loadUsersFailure);
}
更新:
function loadUsersSuccess(result) {
WL.Logger.debug("Feed retrieve success");
busyIndicator.hide();
WL.Logger.debug(JSON.stringify(result));
// if responseJSON is not null user data was returned
if (result.responseJSON != null) {
displayFeeds(result.responseJSON);
} else{
loadUsersFailure();
}
}
基本上有两种带参数的URL:
1、路径参数:
/adapters/UserAdapter/users/{用户名}
2.查询参数:
/adapters/UserAdapter/users?userId={userId}
java 具有查询参数的适配器:
@GET
@Produces("application/json")
@OAuthSecurity(enabled = false)
@Path("/users")
public String getuserById(@QueryParam("userID") String userId)
{
System.out.println(userId);
}
java 带有路径参数的适配器:
@GET
@Produces("application/json")
@OAuthSecurity(enabled = false)
@Path("/users/{userId}")
public String getuserById(@PathParam("userId") String userId)
{
System.out.println(userId);
}
我希望,第二个示例在 java 适配器中回答了您的问题。
我正在学习 MobileFirst Platform 7 的 Java SQL Adapter 教程。
我正在尝试使用 userId = "bjones" 获取用户,但我不知道如何将参数 {userId}
设置到过程 /adapters/UserAdapter/{userId}
.
function loadUsers(){
busyIndicator.show();
var resourceRequest = new WLResourceRequest("/adapters/UserAdapter/", WLResourceRequest.GET);
resourceRequest.setQueryParameter("userId", "bjones");
resourceRequest.send().then(
loadUsersSuccess,
loadUsersFailure
);}
function loadUsersSuccess(result){
WL.Logger.debug("Feed retrieve success");
busyIndicator.hide();
WL.Logger.debug(JSON.stringify(result));
if (result.responseJSON.length>0)
displayFeeds(result.responseJSON);
else
loadUsersFailure();}
function loadUsersFailure(result){
WL.Logger.error("Feed retrieve failure");
busyIndicator.hide();
WL.SimpleDialog.show("Banking Application", "Service not available. Try again later.",
[{
text : 'Reload',
handler : WL.Client.reloadApp
},
{
text: 'Close',
handler : function() {}
}]
);}
我的要求是
localhost:10080/JavaAdapters/adapters/UserAdapter/?userId=bjones
但 JSON 响应包含存储在我的数据库中的所有用户 Image for response
此外,REST 调用类型 @PUT
,路径参数 "userId" 和正文参数:"firstName","lastName","password",怎么样?为了更新用户
根据教程,适配器端点是 /{userId}
,这意味着 userId
不是查询参数,但它是 url 的一部分。您需要更新 loadUsers
函数,以便它在 url 的末尾附加 userId
,因此在您的示例中,完整路径将为 /adapters/UserAdapter/bjones
function loadUsers(){
busyIndicator.show();
var usedId = "bjones";
var resourceRequest = new WLResourceRequest("/adapters/UserAdapter/"+userId, WLResourceRequest.GET);
resourceRequest.send().then(loadUsersSuccess,loadUsersFailure);
}
更新:
function loadUsersSuccess(result) {
WL.Logger.debug("Feed retrieve success");
busyIndicator.hide();
WL.Logger.debug(JSON.stringify(result));
// if responseJSON is not null user data was returned
if (result.responseJSON != null) {
displayFeeds(result.responseJSON);
} else{
loadUsersFailure();
}
}
基本上有两种带参数的URL: 1、路径参数: /adapters/UserAdapter/users/{用户名} 2.查询参数: /adapters/UserAdapter/users?userId={userId}
java 具有查询参数的适配器:
@GET
@Produces("application/json")
@OAuthSecurity(enabled = false)
@Path("/users")
public String getuserById(@QueryParam("userID") String userId)
{
System.out.println(userId);
}
java 带有路径参数的适配器:
@GET
@Produces("application/json")
@OAuthSecurity(enabled = false)
@Path("/users/{userId}")
public String getuserById(@PathParam("userId") String userId)
{
System.out.println(userId);
}
我希望,第二个示例在 java 适配器中回答了您的问题。