补充5 Ah d数据成员和Hanada Bridge

SAPUI5 Add Data into HanaDatabase

我是 SAPUI5 和 HanaDatabase 的新手,目前我正在使用 SAPUI 和 HanaDatabase 创建一个 CRUD 应用程序。我从互联网上阅读了在线教程,但我不太了解它。我按照步骤一步一步往Hana数据库中插入数据,但是失败了。

以下是我的代码。

View.XML

<semantic:SemanticPage id="AddProductPage" headerPinnable="false" toggleHeaderOnTitleClick="false">


        <semantic:titleHeading>
            <Title text="Product"/>
        </semantic:titleHeading>


        <semantic:headerContent>
                <Label text="Product Name" width="100%" id="lb_Productname"/>
                <Input width="60%" id="input_Productname"/>

                <Label text="Product Category" width="100%" id="lb_Productcategory"/>
                <Input width="60%" id="input_Productcategory"/>

                <Label text="Product Description" width="100%" id="lb_Productdescription"/>
                <TextArea width="60%" id="area_Productdescription"/>                

                <Label text="Product Description" width="100%" id="lb_Productprice"/>
                <Input width="60%" id="input_Productprice"/>

                <Label text="" width="100%"/>

                <Button text="Add" width="20%" id="bt_Add" press=""/>
                <Button text="Cancel" width="20%" id="bt_Cancel" press="onClearProduct"/>
        </semantic:headerContent>

</semantic:SemanticPage>

Controller.JS

onInsertProduct: function() {
            var oView = this.getView();
            var oModel = this.getView().getModel();
            var mNewEntry = {};

            mNewEntry.PRODUCTNAME =  oView.byId("input_Productname").getValue();
            mNewEntry.PRODUCTDESCRIPTION = oView.byId("area_Productdescription").getValue();
            mNewEntry.PRODUCTCATEGORY =  oView.byId("input_Productcategory").getValue();
            mNewEntry.PRODUCTPRICE =  oView.byId("input_Productprice").getValue();

            oModel.create("/DATA", mNewEntry, null function(data){

                sap.m.MessageBox.show("Record Insert Successfully", {
                    icon : sap.m.MessageBox.Icon.SUCCESS,
                    title : "Application",
                    styleClass : "sapUiSizeCompact"
                });
            }), function(err){
                sap.m.MessageBox.show("Record insert failed, Please try again", {
                    icon : sap.m.MessageBox.Icon.ERROR,
                    title : "Application",
                    styleClass : "sapUiSizeCompact"
                });
            });

        },

我想你实现了一个 OData 服务来处理后端的数据?

您确定您的 oModel 包含此 OData 服务的模型吗?我使用以下代码,效果很好:

var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/[name of OData-Service/");

    oModel.create("/[name of OData-entity]", mNewEntry, {
        method: "POST",
            success: function(){
                // for example your success message...
            },
            error: function() {
                // for example your error message...
            }
    });

希望这就是您所需要的:)