SAPUI5教程——更改ODataModel默认的请求方式

这里写图片描述

前言

对于ODataModel $batch的请求而言,会自动调用ODataModel UPdate的方法的 merge 请求,这也是默认的请求方式,但是我们的项目当中,往往需要put的请求,那么该如何更改默认的请求方式呢

解决办法

在我们默认maifest.json声明过程中可以通过settings:去更改:

看代码:

"": {
    "type": "sap.ui.model.odata.v2.ODataModel",
    "settings": {
                    "defaultUpdateMethod": "Put"
                }
    }

整个manifest文件:

{
    "_version": "1.5.0",
    "sap.app": {
        "id": "FormDemoCase",
        "type": "application",
        "i18n": "i18n/i18n.properties",
        "applicationVersion": {
            "version": "1.0.0"
        },
        "title": "{{appTitle}}",
        "description": "{{appDescription}}",
        "sourceTemplate": {
            "id": "ui5template.basicSAPUI5ApplicationProject",
            "version": "1.40.12"
        }
    },

    "sap.ui": {
        "technology": "UI5",
        "icons": {
            "icon": "",
            "favIcon": "",
            "phone": "",
            "phone@2": "",
            "tablet": "",
            "tablet@2": ""
        },
        "deviceTypes": {
            "desktop": true,
            "tablet": true,
            "phone": true
        },
        "supportedThemes": [
            "sap_hcb",
            "sap_belize"

        ]
    },

    "sap.ui5": {
        "rootView": {
            "viewName": "FormDemoCase.view.HelloWorld",
            "type": "XML"
        },
        "dependencies": {
            "minUI5Version": "1.30.0",
            "libs": {
                "sap.ui.core": {},
                "sap.m": {},
                "sap.ui.layout": {},
                "sap.ushell": {},
                "sap.collaboration": {},
                "sap.ui.comp": {},
                "sap.uxap": {}
            }
        },
        "contentDensities": {
            "compact": true,
            "cozy": true
        },
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "settings": {
                    "bundleName": "FormDemoCase.i18n.i18n" }
            },
            "": {
                "type": "sap.ui.model.odata.v2.ODataModel",
                "settings": {
                    "defaultUpdateMethod": "Put" }
            }
        },
        "resources": {
            "css": [{
                "uri": "css/style.css"
            }]
        }
    }
}

SAPUI5教程——更改ODataModel默认的请求方式_第1张图片

你可能感兴趣的:(SAP,Fiori,SAPUI5,SAPUI5教程,SAP,Fiori,开发实践)