Jaydata Node Express CRUD服务器端ODATA上的问题
我需要设置一个带有节点的OData服务器。我设法让Jaydata使用Express启动并运行,定义了一个模型,并正确加载了该模型。我可以在SAPUI5表中正确显示条目 基本上,这是我的定位 以下是基本代码段:Jaydata Node Express CRUD服务器端ODATA上的问题,express,odata,sapui5,jaydata,Express,Odata,Sapui5,Jaydata,我需要设置一个带有节点的OData服务器。我设法让Jaydata使用Express启动并运行,定义了一个模型,并正确加载了该模型。我可以在SAPUI5表中正确显示条目 基本上,这是我的定位 以下是基本代码段: // ... // Model.js // $data.Class.define("Cases.User", $data.Entity, null, { Id: { type: "id", key: true, computed: true, nullable: false },
// ...
// Model.js
//
$data.Class.define("Cases.User", $data.Entity, null, {
Id: { type: "id", key: true, computed: true, nullable: false },
FirstName: { type: "string", required:true},
LastName: {type:"string", required:true},
Username: {type:"string", required:true},
Email: {type:"string", required:true},
isAdmin: {type:"boolean"},
Password:{type:"string", minLength: 8}
}, null);
$data.EntityContext.extend("CaseDatabase", {
Users: { type: $data.EntitySet, elementType: Cases.User }
});
$data.Class.defineEx("Cases.Context", [$data.EntityContext,$data.ServiceBase], null, {
User:{ type: $data.EntitySet, elementType: Cases.User }
});
exports = Cases.Context;
从router.js
中提取:
app.use("/api", $data.JayService.OData.Utils.simpleBodyReader());
app.use("/api", $data.JayService.createAdapter(Cases.Context, function (req, res) {
return new Cases.Context({name: "mongoDB", databaseName:"cases", address: "127.0.0.1", port: 27017 });
}));
如上所述,这些链接就像charm一样工作,我可以从MongoDB获得条目:
/api/$metadata和/api/User
当我试图通过SAPUI5客户机添加任何条目时,我就倒霉了。我遵循了与上述问题相同的模式:
模型被正确地绑定到SAPUI5表,正如所说的那样
var oModel = new sap.ui.model.odata.ODataModel("/api");
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
var oTable = sap.ui.getCore().byId("UserList")
oTable.setModel(oModel);
oTable.bindRows("/User");
不起作用的是,当我想添加一个用户条目时。我将数据填入变量中,但将数据发回服务(/api
)总是会导致:
状态405-不允许使用方法
发布到URI:/api/User
将导致状态500
客户端代码:
...
OData.request({
requestUri: "/api/",
method: "POST",
data: user
},
function(insertedItem) {
console.log(insertItem);
},
function(err) {
console.log(err);
});
...
我注意到的另一件事是xml:base
看起来非常奇怪(localhost:3000/api
):
包含“未定义”。但是,我不知道这是否是我问题的根源,也不知道如何消除未定义的错误。我找到并调试了相同的奇怪uri库,并通过JayService.js中的更改进行了修复 更改此行: req.fullRoute=(req.baseRoute | |(schema+':/“+req.headers.host))+app.route强> 为此内容: req.fullRoute=(req.baseRoute | |(schema+'://'+req.headers.host))+req.baseUrl强>
然后您可以实际请求生成的URI并获得结果;-) 谢谢,也谢谢你纠正了一些问题,我解决了我的问题。这是我的属性(FirstName与FirstName)中的一个错误。
<service xml:base="http://localhost:3000undefined/">