Web编程学习七:使用JPA + RESTful Web Service + SAPUI5来创建Web应用
来源:互联网 发布:网络安全法公安机关 编辑:程序博客网 时间:2024/06/07 02:58
在之前的例子学习了如何使用JPA,如何通过Apache olingo来将JPA数据库自动转化为RESTful Web Service。
学习了如何使用SAPUI5,现在我来把它们整合起来。
开发环境:
开发环境是:Eclipse Juno, MySQL 5.5,olingo 1.2,EclipseLink 2.4, Tomcat 7, SAPUI5 1.18
这里数据层就直接使用上一个练习完成的jpa2项目,它实现了一个对后台数据库表employee操作的RESTful Web Service,
url: http://localhost:8080/jpa2/Employee.svc/
1.安装SAP提供的Eclipse SAPUI5插件。
https://tools.hana.ondemand.com
2.创建一个SAPUI5的Web Project,名字叫sapui5
3.由于我的服务是local的,所以需要使用proxy来访问,修改一下web.xml
添加:
<servlet><servlet-name>SimpleProxyServlet</servlet-name><servlet-class>com.sap.ui5.proxy.SimpleProxyServlet</servlet-class></servlet><servlet-mapping><servlet-name>SimpleProxyServlet</servlet-name><url-pattern>/proxy/*</url-pattern></servlet-mapping><context-param><param-name>com.sap.ui5.proxy.REMOTE_LOCATION</param-name><param-value>http://localhost:8080</param-value></context-param>
4.修改index.html文件:
<!DOCTYPE HTML><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv='Content-Type' content='text/html;charset=UTF-8' /><script src="resources/sap-ui-core.js" id="sap-ui-bootstrap"data-sap-ui-libs="sap.ui.commons, sap.ui.table"data-sap-ui-theme="sap_bluecrystal"></script><script>//One place for defining service URLs - either in the index.html file, //or in one separate .js file which needs to be included.//The application is responsible for exchanging the URLs before checking in and //after checking out to SAPUI5 Repository;//or using a helper function getServiceUrl for which also the application //is responsible.//var serviceUrl = "/mypath/myservice"; //url when running on the ABAP system//var serviceUrl = "proxy/mypath/myservice"; //url when running locally in Eclipsevar serviceUrl = getServiceUrl("/jpa2/Employee.svc/");function getServiceUrl(sServiceUrl) {//for local testing prefix with proxy//if you and your team use a special host name or IP like 127.0.0.1 for localhost please adapt the if statement below if (window.location.hostname == "localhost") {return "proxy" + sServiceUrl;} else {return sServiceUrl;}}</script><script>// create the DataTable controlvar oTable = new sap.ui.table.Table({editable : true});// define the Table columnsvar oControl = new sap.ui.commons.TextView({text : "{Id}"}); // short binding notationoTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "ID"}),template : oControl,sortProperty : "id",filterProperty : "id",width : "100px"}));// define the Table columnsvar oControl = new sap.ui.commons.TextView({text : "{FirstName}"}); // short binding notationoTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "First Name"}),template : oControl,sortProperty : "firstName",filterProperty : "firstName",width : "100px"}));// define the Table columnsvar oControl = new sap.ui.commons.TextView({text : "{LastName}"}); // short binding notationoTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "Last Name"}),template : oControl,sortProperty : "lastName",filterProperty : "lastName",width : "100px"}));var oModel = new sap.ui.model.odata.ODataModel(serviceUrl);oTable.setModel(oModel);oTable.bindRows("/Employees");// finally place the Table into the UIoTable.placeAt("content");</script></head><body class="sapUiBody" role="application"><div id="content"></div></body></html>
这里主要就是创建一个table组件,然后创建一个odata model,然后它们绑定一下就行了。
5.部署项目在Tomcat上,运行:
6.小结:在得到了RESTful的service以后,进行web和移动开发以后就非常方便了,而使用SAPUI5则变得更方便了,不仅界面漂亮,还可以大大提高开发效率。
2 0
- Web编程学习七:使用JPA + RESTful Web Service + SAPUI5来创建Web应用
- 使用JPA + RESTful Web Service + SAPUI5来创建Web应用
- Web编程学习三: 使用SAPUI5来创建Web应用UI
- 使用SAPUI5来创建Web应用UI
- Web编程学习五: 使用Jersey和JPA来创建RESTful WebService
- Web编程学习二: 使用JPA结合JSF来创建Web应用
- Web编程学习六:使用Apache olingo将JPA数据库操作转化为RESTful Web Service
- Web编程学习四: 使用Jersey来创建RESTful WebService
- Web编程学习一: 使用JSF来创建Web应用
- SAP前端——使用SAPUI5来创建Web应用UI
- 使用JAX-RS创建RESTful Web Service
- 使用JAX-RS创建RESTful Web Service
- 使用JAX-RS创建RESTful Web Service
- 使用JAX-RS创建RESTful Web Service
- 使用Java创建RESTful Web Service
- 使用spring创建一个RESTful Web Service
- 使用Java创建RESTful Web Service
- 使用JAX-RS创建RESTful Web Service
- 黑马程序员-有关Collection的总结
- 第四、五周作业
- 网络121第5周实验——GUI编程及JDK API的使用
- java多线程回顾(一)
- Legal or Not
- Web编程学习七:使用JPA + RESTful Web Service + SAPUI5来创建Web应用
- Ruby中的绑定和eval
- 第三周作业2
- 黑马程序员—网络编程入门基础
- From《Expert C Programming》01
- 15 Linux更改权限解决新建用户不能读写创建文件/文件夹的问题
- Web编程学习八:通过Apache Cordova将Web应用移动化
- 选择排序 自己终于会写了
- java笔记之内部类