Fiori 初学记录----怎么调用后端系统odata 服务实现简单的CURD

1.对上面的内表做一个简单的增删改查的操作
 SEGW 创建odata 项目,实现增删改查方法。如下图

2.odata 准备完毕后,打开vscode



下一步等待项目生成

把下面这个目录的视图:替换一下:

View1.view.xml 代码:
 

<mvc:ViewcontrollerName="project4.controller.View1"xmlns:mvc="sap.ui.core.mvc"displayBlock="true"xmlns="sap.m"xmlns:myform="sap.ui.layout.form"
><App id="_IDGenApp1"><Page id="page"><content><Tableid="_IDGenTable1"items="{/ZUSERDATASet}"selectionChange="onSelect"mode="SingleSelectLeft"fixedLayout="false"><columns><Column id="_IDGenColumn1"><Textid="_IDGenText1"text="Employee Id"/></Column><Column id="_IDGenColumn2"><Textid="_IDGenText2"text="Name"/></Column><Column id="_IDGenColumn3"><Textid="_IDGenText3"text="Salary"/></Column><Column id="_IDGenColumn4"><Textid="_IDGenText4"text="Age"/></Column></columns><items><ColumnListItem id="_IDGenColumnListItem1"><cells><Textid="_IDGenText5"text="{Id}"/></cells><cells><Textid="_IDGenText6"text="{Name}"/></cells><cells><Textid="_IDGenText8"text="{Salary}"/></cells><cells><Textid="_IDGenText7"text="{Age}"/></cells></ColumnListItem></items></Table></content><Titleid="_IDGenTitle1"text="Employee Details"class="myformTitle"/><myform:SimpleFormid="cMyform"editable="true"><myform:content><Labelid="_IDGenLabel1"text="Emp_Id"/><Textid="_IDGenText9"text="{Id}"/><Labelid="_IDGenLabel2"text="Name"/><Textid="_IDGenText10"text="{Name}"/><Labelid="_IDGenLabel4"text="Salary"/><Textid="_IDGenText12"text="{Salary}"/><Labelid="_IDGenLabel5"text="City"/><Textid="_IDGenInput5"text="{City}"/></myform:content></myform:SimpleForm><footer><Bar id="_IDGenBar1"><contentRight><Buttonid="_IDGenButton1"text="Create"press="oCreateEmpPopup"type="Emphasized"/><Buttonid="_IDGenButton"text="Read"press="oSearchEmpPopup"type="Emphasized"/><Buttonid="_IDGenButton2"text="Update"press="oUpdateEmpPopup"type="Emphasized"/><Buttonid="_IDGenButton3"text="Delete"press="oDeleteEmp"type="Negative"/></contentRight></Bar></footer></Page></App>
</mvc:View>

把下面的红色框替换成自己的项目名

下面的代码

View1.controller.js
代码:
 

sap.ui.define(["sap/ui/core/mvc/Controller","sap/m/MessageToast","sap/m/MessageBox"
],/*** @param {typeof sap.ui.core.mvc.Controller} Controller*/function (Controller, MessageToast, MessageBox) {"use strict";return Controller.extend("project4.controller.View1", {onInit: function () {},onSelect: function (oEvent) {var sPath = oEvent.oSource._aSelectedPathssPath = sPath[0].split("/")sPath = sPath[1]var myForm = this.getView().byId("cMyform")myForm.bindElement("/" + sPath)this.oPath = sPath},oCreateEmpPopup: function () {if (!this.oFragment) {this.oFragment = new sap.ui.xmlfragment("project4.fragment.CreateForm", this)this.getView().addDependent(this.oFragment)this.oFragment.open()}else {this.oFragment.open()}},oCloseButton: function () {this.oFragment.close()this.oFragment.destroy(true)this.oFragment = null},oUpdateEmpPopup: function () {if (!this.oReadEmpFragment) {this.oReadEmpFragment = new sap.ui.xmlfragment("project4.fragment.ReadForm", this)var myForm = sap.ui.getCore().byId("cFragmentMyform")myForm.bindElement("/" + this.oPath)this.getView().addDependent(this.oReadEmpFragment)this.oReadEmpFragment.open()}else {this.oReadEmpFragment.open()}},oCloseReadButton: function () {this.oReadEmpFragment.close()this.oReadEmpFragment.destroy(true)this.oReadEmpFragment = null},oCreateEmp: function () // FOR CREATING NEW RECORD ************{var UserName = sap.ui.getCore().byId('_IDGenInput2').getValue()var UserSalary = sap.ui.getCore().byId('_IDGenInput3').getValue()var UserId = sap.ui.getCore().byId('_IDGenInput1').getValue()var UserAge = sap.ui.getCore().byId('_IDGenInput4').getValue()var UserCity = sap.ui.getCore().byId('_IDGenInput5').getValue()var oAddEmpData = {}oAddEmpData.Name = UserNameoAddEmpData.Salary = UserSalaryoAddEmpData.Id = UserIdoAddEmpData.Age = UserAgeoAddEmpData.City = UserCitythis.getView().getModel().create("/ZUSERDATASet", oAddEmpData, {method: "POST",success: function (data) {MessageToast.show("Employee Created Successfully");},error: function (data) {MessageToast.show(data);},});},oUpdateEmp: function () // FOR UPDATING RECORD *************{var UserName = sap.ui.getCore().byId('_IDGenInput2').getValue()var UserSalary = sap.ui.getCore().byId('_IDGenInput4').getValue()var UserId = sap.ui.getCore().byId('_IDGenInput1').getValue()var oAddEmpData = {}oAddEmpData.Name = UserNameoAddEmpData.Salary = UserSalarythis.getView().getModel().update("/ZUSERDATASet('" + UserId + "')",oAddEmpData, {method: "PATCH",success: function (data) {MessageToast.show("Employee update Successfully with number");},error: function (data) {MessageToast.show(data);}});},oDeleteEmp: function () // FOR DELETING RECORD **************{this.oPaththis.getOwnerComponent().getModel().remove("/ZUSERDATASet('" + this.oPath.split("'")[1] + "')", {method: "DELETE",success: function (data) {MessageToast.show("Customer deleted Successfully");},error: function (Error) {sap.m.MessageToast.show(Error);}});},oSearchEmpPopup: function () {if (!this.SearchEmp) {this.SearchEmp = new sap.ui.xmlfragment("project4.fragment.SearchEmp", this)this.getView().addDependent(this.SearchEmp)this.SearchEmp.open()}else {this.SearchEmp.open()}},oReadEmp1: function () // FOR READING A SINGLE RECORD BY USING ID OF EMPLOYEE{var SearchInp = sap.ui.getCore().byId("_IDGenInput1").getValue()this.getOwnerComponent().getModel().read("/ZUSERDATASet('" + SearchInp + "')", {method: "GET",success: function (data) {MessageBox.success("ID :- " + data.Id + " " + "Name :- " + data.Name + " " + "Salary :- " + data.Salary);},error: function (Error) {sap.m.MessageToast.show(Error);}});},oCloseSearchButton: function () {this.SearchEmp.close()this.SearchEmp.destroy(true)this.SearchEmp = null}});});

需要把代码里面的红色框换成自己的项目名字

创建红色框内容CreateForm.fragment.xml
 

<c:FragmentDefinitionxmlns="sap.m"xmlns:c="sap.ui.core"xmlns:myform="sap.ui.layout.form"
><Dialogid="_IDGenDialog1"contentWidth="500px"><content><myform:SimpleFormid="_IDGenSimpleForm1"editable="true"><myform:content><Labelid="_IDGenLabel1"text="Emp_Id"/><Inputid="_IDGenInput1"placeholder="Enter Employee Id"/><Labelid="_IDGenLabel2"text="Name"/><Inputid="_IDGenInput2"placeholder="Enter your Name"/><Labelid="_IDGenLabel3"text="Salary"/><Inputid="_IDGenInput3"placeholder="Enter your Salary"/><Labelid="_IDGenLabel4"text="Age"/><Inputid="_IDGenInput4"placeholder="Enter your Age"/><Labelid="_IDGenLabel5"text="City"/><Inputid="_IDGenInput5"placeholder="Enter your City"/></myform:content></myform:SimpleForm></content><customHeader><Bar id="_IDGenBar1"><contentLeft><Textid="_IDGenText1"text="Add Employee"/></contentLeft><contentRight><Buttonid="_IDGenButton1"icon="sap-icon://decline"press="oCloseButton"/></contentRight></Bar></customHeader><buttons><Buttonid="_IDGenButton2"text="Add"icon="sap-icon://add"press="oCreateEmp"type="Emphasized"/></buttons></Dialog>
</c:FragmentDefinition>

ReadForm.fragment.xml
 

<c:FragmentDefinitionxmlns="sap.m"xmlns:c="sap.ui.core"xmlns:myform="sap.ui.layout.form"
><Dialogid="_IDGenDialog1"contentWidth="500px"><content><myform:SimpleFormeditable="true"id="cFragmentMyform"><myform:content><Labelid="_IDGenLabel1"text="Emp_Id"/><Inputid="_IDGenInput1"value="{Id}"/><Labelid="_IDGenLabel2"text="Name"/><Inputid="_IDGenInput2"value="{Name}"/><Labelid="_IDGenLabel4"text="Salary"/><Inputid="_IDGenInput4"value="{Salary}"/></myform:content></myform:SimpleForm></content><customHeader><Bar id="_IDGenBar1"><contentLeft><Textid="_IDGenText1"text="Employee information"/></contentLeft><contentRight><Buttonid="_IDGenButton1"icon="sap-icon://decline"press="oCloseReadButton"/></contentRight></Bar></customHeader><buttons><Buttonid="_IDGenButton2"text="Update"press="oUpdateEmp"/></buttons></Dialog>
</c:FragmentDefinition>

SearchEmp.fragment.xml
 

<c:FragmentDefinitionxmlns="sap.m"xmlns:c="sap.ui.core"xmlns:myform="sap.ui.layout.form"
><Dialog id="_IDGenDialog1"><content><myform:SimpleFormid="_IDGenSimpleForm1"editable="true"><Inputid="_IDGenInput1"placeholder="Enter Emp_Id"/><Buttonid="_IDGenButton2"press="oReadEmp1"icon="sap-icon://search"/></myform:SimpleForm></content><customHeader><Bar id="_IDGenBar1"><contentLeft><Textid="_IDGenText1"text="Search Employee"/></contentLeft><contentRight><Buttonid="_IDGenButton1"icon="sap-icon://decline"press="oCloseSearchButton"/></contentRight></Bar></customHeader></Dialog>
</c:FragmentDefinition>

运行app  输入命令  npm start 
输出界面:


可以再yaml.xml 里面配置本地SDK

    - name: fiori-tools-servestaticafterMiddleware: compressionconfiguration:paths:- path: /resourcessrc: "C://SDK//resources"- path: /test-resourcessrc: "C://SDK//test-resources"


参考文章:How to Create OData Service and CRUD Operations fr... - SAP Community

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/diannao/86924.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

OpenCV CUDA模块图像变形------对图像进行GPU加速的仿射变换函数warpAffine()

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 该函数用于对图像进行 GPU 加速的仿射变换&#xff08;Affine Transformation&#xff09;&#xff0c;是 cv::warpAffine 的 CUDA 版本。支持平…

语音增强方法

一、音量增强 音量增强&#xff0c;顾名思义就是音量的调大和调小&#xff0c;通过对音量进行增强可以使得模型更好的泛化。防止数据只有小音量时&#xff0c;当有大音量传入时模型不能很好的进行识别。 下面是我对音量增强生成频谱图进行可视化的结果 上面的一个图片是音量…

内网渗透测试技巧与利用操作手册(SMB / MSSQL / LDAP)

SMB 枚举与利用清单 &#x1f50d; SMB 枚举与连接 # 尝试空会话连接&#xff08;Null Session&#xff09; smbclient -N -U "" -L \\<IP> smbclient -N -U "test" -L \\<IP> smbclient -N -U "Guest" -L \\<IP># 下载共享…

ADB(Android Debug Bridge)Android官方调试工具及常用命令

ADB的定义 ADB&#xff08;Android Debug Bridge&#xff09;是Android官方提供的调试工具&#xff0c;属于Android SDK的一部分。它通过命令行与Android设备通信&#xff0c;支持安装应用、调试、文件传输、日志抓取等功能&#xff0c;适用于开发、测试及高级用户场景。 ADB工…

再现重大BUG,微软紧急撤回Win 11六月更新

BUG年年有&#xff0c;今年特别多&#xff01; Windows 11发布这近4年来&#xff0c;咱们算是一路见证了其「要么在修复BUG&#xff0c;要么在修复BUG路上」这么一件壮举。 最新的6月Windows 11 24H2更新&#xff08;版本号KB5060842&#xff09;&#xff0c;微软带来了多项改…

ROS2 工作空间中, CMakeLists.txt, setup.py和 package.xml的作用分别是?

提问 ROS2 工作空间中, CMakeLists.txt&#xff0c; setup.py和 package.xml的作用分别是&#xff1f; 回答 在一个 ROS 2 包&#xff08;package&#xff09;里&#xff0c;这三个文件各司其职&#xff1a; package.xml 作用&#xff1a;声明包的元信息和依赖关系&#xff…

Untiy打包安卓踩坑

Untiy 版本&#xff1a;unity6.1 运行环境&#xff1a;Win11 报错一&#xff1a; Assembly ‘Assets/ExternalDependencyManager/Editor/1.2.183/Google.IOSResolver.dll’ will not be loaded due to errors: 解决方法&#xff1a;通过在 Unity Hub 中下载 iOS 包来解决 报错…

2025最新版!Windows Python3 超详细安装图文教程(支持 Python3 全版本)

大家好&#xff0c;我是你们的编程搬砖工~ 今天给大家安排一篇超级详细、超接地气、纯小白友好的《Python 安装教程 for Windows》&#xff0c;从下载到安装&#xff0c;从环境变量到验证&#xff0c;手把手带你装好 Python&#xff0c;不管你是 Python3.7、3.9、3.10 还是 3.1…

【IEEE/EI/Scopus检索】2025年第五届机器学习与大数据管理国际会议 (MLBDM 2025)

2025年第五届机器学习与大数据管理国际会议 (MLBDM 2025) 2025 5th International Conference on Machine Learning and Big Data Management(MLBDM 2025)会议地点&#xff1a;南京&#xff0c;中国 时间&#xff1a;2025年12月26日- 28日 ● 会议简介 2025年第五届机器学习…

前端实现ios26最新液态玻璃效果!

先看效果图 实现步骤 先定义玻璃元素和液态滤镜 <!--玻璃容器--> <div class"glass-container"><!--使用液态滤镜--><div class"glass-filter"></div><!--边沿效果--><div class"glass-specular">…

麒麟系统集成开发环境Kylin-IDE初体验,菜鸟小白入门教程

一、安装Kylin-IDE 1、打开应用商店&#xff0c;转到“软件”->“开发”页面&#xff0c;找到“Kylin-IDE”&#xff0c;点下载。&#xff08;也可以在搜索栏搜索Kylin-IDE&#xff09; 2、等待Kylin-IDE下载并自动安装完成。 3、双击桌面的Kylin-IDE图标。 4、自动弹出“开…

Python爬虫实战:研究Bleach库相关技术

一、引言 1.1 研究背景与意义 随着互联网的快速发展,网络上的数据量呈爆炸式增长。网络爬虫作为一种自动获取网页内容的技术,能够高效地从互联网上收集所需信息,为数据分析、信息检索、舆情监测等应用提供基础。然而,爬取到的网页内容往往包含大量的 HTML 标签、JavaScri…

分布假设学习笔记

文章目录 分布假设学习笔记自然语言处理中的分布假设应用场景适用范围 Word2vec、BERT和GPTWord2vecBERTGPT 假设成立吗 分布假设学习笔记 自然语言处理中的分布假设 分布假设&#xff08;Distributional Hypothesis&#xff09;是指&#xff1a;词语在相似上下文中出现&…

提升开发思维的设计模式(上)

1. 设计模式简介 [设计模式]&#xff08;Design pattern&#xff09; 是解决软件开发某些特定问题而提出的一些解决方案也可以理解成解决问题的一些思路。通过设计模式可以帮助我们增强代码的[可重用性]、可扩充性、 可维护性、灵活性好。我们使用设计模式最终的目的是实现代码…

LINUX613计划测put

FTP put ┌────────────────────────────────────────────────────────────────────┐│ • MobaXterm 20.0 • ││ (SSH client, X-serv…

NB-IoT-下行同步、广播信道和信号

这一篇主要讲解以下NPSS/NSSS/NPBCH信号的具体细节。还是依然先分析时频资源&#xff0c;再分析具体信号细节。 1、NPSS信道和信号 NPSS信号总是在每个无线帧的子帧5上。使用符号为3~13个OFDM符号&#xff0c;子载波使用0~10号&#xff08;11个子载波&#xff09;。如果部署为…

Java TCP网络编程核心指南

Java网络编程中TCP通信详解 TCP (Transmission Control Protocol) 是互联网中最核心的传输层协议&#xff0c;提供可靠的、面向连接的字节流传输服务。在Java网络编程中&#xff0c;TCP通信主要通过Socket和ServerSocket类实现。 一、TCP核心特性与Java实现 特性描述Java实现…

SVN迁移Git(保留历史提交记录)

第一步&#xff1a;安装git 下载地址&#xff1a;https://gitforwindows.org/ 第二步&#xff1a;先创建一个git创库&#xff0c;&#xff08;创建过程忽略&#xff09; 第三步&#xff1a;本地新建一个空的项目文件夹&#xff0c;用于存放要迁移的项目代码&#xff0c;我这创…

9.IP数据包分片计算

IP数据报分片计算 题目1&#xff1a;主机发送5400字节数据&#xff0c;MTU1400字节&#xff08;IPv4&#xff09;&#xff0c;填写分片后的字段值。 解答&#xff1a; 分片规则&#xff1a; 每片数据长度尽量接近MTU&#xff08;1400B&#xff09;&#xff0c;IP首部20B&…

pmset - 控制 macOS 系统电源、睡眠、唤醒与节能

文章目录 NAME概要描述SETTINGSETTINGSGETTING安全睡眠参数待机参数UPS 专用参数计划事件参数电源参数说明其他参数示例另请参阅文件 NAME pmset – manipulate power management settings概要 pmset [-a | -b | -c | -u] [setting value] [...]pmset -u [haltlevel percent]…