gpt4 book ai didi

android - Strongloop/Loopback findAll 功能返回 null

转载 作者:行者123 更新时间:2023-11-30 02:50:33 25 4
gpt4 key购买 nike

我正在结合 Strongloop/Loopback 开发 Android 应用程序。我已将我的数据存储在 MySQL 数据库中,使用 Strongloop/Loopback 映射它没有问题。但是,当使用 Strongloop/Loopback 从数据库中检索值时,列表总是返回一个大小但具有空值。无法弄清楚出了什么问题。有人可以帮我吗?非常感谢:)

这是我从 Strongloop 访问时对数据库的 json 响应:

[
{
"rewards_image_name": "http://x.x.x.x/projects/images/rewards_1.png",
"rewards_equivalent_points": "10",
"id": 1 }, {
"rewards_image_name": "http://x.x.x.x/projects/images/rewards_2.png",
"rewards_equivalent_points": "20",
"id": 2 }, {
"rewards_image_name": "http://x.x.x.x/projects/images/rewards_3.png",
"rewards_equivalent_points": "30",
"id": 3 }, {
"rewards_image_name": "http://x.x.x.x/projects/images/rewards_4.png",
"rewards_equivalent_points": "40",
"id": 4 }
]

这是我获取列表的代码:

    StrongloopClient strongloopClient = new StrongloopClient(this.context);
RestAdapter adapter = strongloopClient.getLoopBackAdapter("Rewards", "GET");
StrongloopRewardsModelRepository strongloopRewardsModelRepository = adapter.createRepository(StrongloopRewardsModelRepository.class);
strongloopRewardsModelRepository.findAll(new ListCallback<StrongloopRewardsModel>() {

@Override
public void onSuccess(List<StrongloopRewardsModel> arg0) {
Log.e("", "GetAllRewards success: " + arg0.get(0).getEquivalentPoints());

}

@Override
public void onError(Throwable arg0) {
Log.e("", "GetAllRewards error: " + arg0);
}
});

这是 StrongloopClient:

public class StrongloopClient {

private Context context;
private RestAdapter adapter;

public StrongloopClient(Context contxt) {
context = contxt;
}

public RestAdapter getLoopBackAdapter(String transaction, String operation) {
if (adapter == null) {
adapter = new RestAdapter(context, "http://192.168.44.101:3000/api");
adapter.getContract().addItem(
new RestContractItem("/" + transaction, operation),
transaction);
}
return adapter;
}

这是存储库的代码:

public class StrongloopRewardsModelRepository extends ModelRepository<StrongloopRewardsModel>{

public StrongloopRewardsModelRepository() {
super("Rewards", "Rewards", StrongloopRewardsModel.class);
}
}

这是模型:

public class StrongloopRewardsModel extends Model {

private Integer rewardsImageId;
private String rewardImageName;
private String equivalentPoints;

public Integer getRewardsImageId() {
return rewardsImageId;
}
public void setRewardsImageId(Integer rewardsImageId) {
this.rewardsImageId = rewardsImageId;
}
public String getRewardImageName() {
return rewardImageName;
}
public void setRewardImageName(String rewardImageName) {
this.rewardImageName = rewardImageName;
}
public String getEquivalentPoints() {
return equivalentPoints;
}
public void setEquivalentPoints(String equivalentPoints) {
this.equivalentPoints = equivalentPoints;
}
}

最佳答案

终于,我找到了问题所在。 POJO 应该匹配在 models.json 中创建的模型的字段。谢谢你的时间。

但是,我的另一个问题是,当我使用过滤器进行查询时,例如将过滤器作为“参数”的一部分传递给 Strongloop 适配器时,它似乎返回所有模型实例而不是过滤的模型实例。来 self 的问题的相同代码,只是 getLoopbackAdapter("Rewards","GET") 变成了"Rewards?filter[where][rewards_equivalent_points]=10","GET")。有什么想法为什么会这样吗?谢谢:)

关于android - Strongloop/Loopback findAll 功能返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24256461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com