我目前正在尝试学习SAPUI5和OData的基础知识。我正在构建一个简单的应用程序,其中将员工数据显示在表中,您可以添加一个新员工,其数据将被写入SAP后端。
所有GET请求均有效,而POST请求始终会导致服务器错误(500)。我的创建方法是否格式错误,还是我忘记了某些内容(特殊标头等)? (我知道我实际上应该使用odata.v2,但仅出于此示例的目的……我只是没有看到明显的错误?)
sap.ui.controller("zemployee_crud.EmpTable", {
onInit: function() {
var oView = this.getView();
var oTable = this.byId("employeeTable");
var oTemplate = new sap.m.ColumnListItem({
cells: [new sap.m.Text({
text: "{Empid}"
}), new sap.m.Text({
text: "{Empname}"
}), new sap.m.Text({
text: "{Empadd}"
})]
});
var sServiceUrl = "proxy/http/<server>:<port>/sap/opu/odata/sap/ZEMPLOYEE_SRV";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, false);
this.getView().setModel(oModel);
oTable.bindAggregation("items", {
path: "/EmployeeSet",
template: oTemplate
});
},
Save: function() {
var oId = this.getView().byId("Id").getValue();
var oName = this.getView().byId("Name").getValue();
var oAddress = this.getView().byId("Address").getValue();
var oDialog = this.getView().byId("Dialog");
var oEntry = {};
oEntry.Empid = oId;
oEntry.Empname = oName;
oEntry.Empadd = oAddress;
var oModel = this.getView().getModel();
oModel.create("/EmployeeSet", oEntry, null, function (response) {
alert("Success!");
// handle response
}, function (Error) {
alert("Fail!");
// handle response
});
}
答案 0 :(得分:0)
这是UI5开发中的常见情况。 SAP Gateway Server不会告诉前端确切的错误,因为那可能会泄漏您不希望的数据。
要找出确切的问题是什么,您应该转到后端的事务/ IWFND / ERROR_LOG。那里的请求应该是可见的,您可以看到正是导致此错误的原因。
答案 1 :(得分:0)
最后发现了错误-通过Eclipse创建的BSP应用程序存在问题。解决此问题后,POST请求就可以正常工作。