OFBiz进阶之HelloWorld(三)CRUD操作
参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guide
创建、更新和删除操作一个实体将由minilang 写成的服务实现。为了更好的理解这些内容,我们写自己的服务来完成这些操作,之后我们将通过调用已经实现的服务来完成。
要做这些,我们将采用会员模型的实体:
--Party
--Person
一个人是一会员,所以创建一个人先得创建一类型是partyTypeId="PERSON"的会员。
所以有两种方式做这些:
1. 创建一个服务来进行带有类型Person 的会员创建工作。
2. 在服务中先创建一个会员,再创建个人。
1. Writing Services
a. 在practice下创建目录servicedef,此目录将包含所有服务定义文件,如:services.xml,secas.xml。
注:如果一个服务用java编写,应放到src目录,如果是用minilang编写,应放到script目录。
比如java applications/party/src/org/ofbiz/party/party/PartyServices.java和minilang applications/party/script/org/ofbiz/party/party/PartyInvitationServices.xml;
各自的类路径和文件路径将在服务定义中体现。
b. 在控制器(controller.xml)中你必须创建一个入口为执行服务的请求和设置响应:
<request-map uri="createPracticePerson">
<security https="true" auth="true"/>
<event type="service" invoke="createPracticePerson"/>
<response name="success" type="view" value="PersonForm"/>
</request-map>
c. 现在所有写好的服务必须在服务器启动时装载,因此需要在ofbiz-component.xml为服务定义(service definition)创建一个条目(entry)
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
注意:对服务定义的任何修改均需要重启服务器才能生效。
2. Writing CRUD Operations for Party Entity
开始我们将为会员写服务,然后当写创建Person 服务时将调用会员的服务。
a. 在servicedef 下创建文件services.xml
b. 为Party实体定义CRUD操作的服务。服务的名称是createPracticeParty, updatePracticeParty, deletePracticeParty,并且指定正确的路径到这些服务实现的文件,例如/framework/example/script/org/ofbiz/example/example/ExampleServices.xml。
c. 为这些服务的实现在你的组件目录中创建目录结构和PracticeServices.xml文件。
(实现可参考Example组件的services.xml和ExampleServices.xml文件。)
注意:不要使用<override>标签,它在教程随后的介绍中。
从这里开始,你想运行这些服务的话,可以通过webtools 运行这些服务:webtools--> Run Service . 这样你可以测试你的服务。
你应该阅读http://markmail.org/message/dj4wvtm4u2nxoz3r。这功能近来已经增加,与对实体写CRUD操作的传统方式不同。
新功能让你仅定义这些服务,通过说起你想运行的操作。基本上设计引挚属性为"entity-auto"和调用(invoke)属性为"create", "update", or "delete"。你可以看下example 组件的services.xml 中的下列代码:
<service name="createExample" default-entity-name="Example" engine="entity-auto" invoke="create" auth="true">
<description>Create a Example</description>
<permission-service service-name="exampleGenericPermission" main-action="CREATE"/>
<auto-attributes include="pk" mode="OUT" optional="false"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>
<override name="exampleTypeId" optional="false"/>
<override name="statusId" optional="false"/>
<override name="exampleName" optional="false"/>
</service>
engine="entity-auto" invoke="create"为缺省实体"Example."做创建记录的角色。
作为练习你可以做更进一步,这些步骤在帮助你理解概念,你仅能在你的代码中练习上面所给模式。
3. Writing CRUD Operations for Person Entity
为个人person 实体创建记录需要有partyId,因此首先调用createPracticeParty服务得到partyId后再去创建person记录。
我们将在person 实体列表表单下面增加一个附加的表单。这个表单将调用这个服务来创建一个person 记录。
a. 创建用于创建person的附加表单,并且把下面的person 表单加在同一个screen 中。
<form name="CreatePerson" type="single" target="createPracticePerson">
<auto-fields-service service-name="createPracticePerson"/>
<field name="submitButton" title="Create" widget-style="smallSubmit"><submit button-type="button"/></field>
</form>
b. 为 person 实体写CRUD 操作,这个就是在services.xml 中createPracticePerson 的代码。
<service name="createPracticePerson" default-entity-name="Person" engine="simple"
location="component://practice/script/org/hotwax/practice/PracticeServices.xml" invoke="createPracticePerson" auth="true">
<description>Create a Person</description>
<auto-attributes include="pk" mode="OUT" optional="false"/>
<attribute name="salutation" mode="IN" type="String" optional="true"/>
<attribute name="firstName" mode="IN" type="String" optional="false"/>
<attribute name="middleName" mode="IN" type="String" optional="true"/>
<attribute name="lastName" mode="IN" type="String" optional="false"/>
<attribute name="suffix" mode="IN" type="String" optional="true"/>
</service>
Update和Delete与上面类似。
c. 用可编辑的字段转换List 表单 (参考: ListExampleItems from ExampleForms.xml) ,在里面加入更新和删除选项,也把附加的表单加入同一screen 中。
d. 为这些服务增加控制项,是通过这表单来调用的。
e. 运行应用,查看效果
OFBiz进阶之HelloWorld(三)CRUD操作的更多相关文章
- OFBiz进阶之HelloWorld(二)创建热部署模块
参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...
- OFBiz进阶之HelloWorld(五)创建新实体
参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...
- OFBiz进阶之HelloWorld(一)创建热部署模块
创建热部署模块 参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Developm ...
- 【翻译】MongoDB指南/CRUD操作(三)
[原文地址]https://docs.mongodb.com/manual/ CRUD操作(三) 主要内容: 原子性和事务(Atomicity and Transactions),读隔离.一致性和新近 ...
- 第三百六十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)基本的索引和文档CRUD操作、增、删、改、查
第三百六十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)基本的索引和文档CRUD操作.增.删.改.查 elasticsearch(搜索引擎)基本的索引 ...
- 【Mybatis】MyBatis对表执行CRUD操作(三)
本例在[Mybatis]MyBatis配置文件的使用(二)基础上继续学习对表执行CRUD操作 使用MyBatis对表执行CRUD操作 1.定义sql映射xml文件(EmployeeMapper.xml ...
- 【翻译】MongoDB指南/CRUD操作(一)
[原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(一) 主要内容:CRUD操作简介,插入文档,查询文档. CRUD操作包括创建.读取.更新和删 ...
- MongoDB的CRUD操作
1. 前言 在上一篇文章中,我们介绍了MongoDB.现在,我们来看下如何在MongoDB中进行常规的CRUD操作.毕竟,作为一个存储系统,它的基本功能就是对数据进行增删改查操作. MongoDB中的 ...
- 【Java EE 学习 44】【Hibernate学习第一天】【Hibernate对单表的CRUD操作】
一.Hibernate简介 1.hibernate是对jdbc的二次开发 2.jdbc没有缓存机制,但是hibernate有. 3.hibernate的有点和缺点 (1)优点:有缓存,而且是二级缓存: ...
随机推荐
- Android之ListView常用技巧
ListView是一个非常常用的列表控件,虽然在5.x时代ListView的风头正在逐渐的被RecyclerView抢去,但是ListView的使用范围依然十分广泛. 接下来的ListView的常用技 ...
- c语言排序算法总结
一.希尔(Shell)排序法 /* Shell 排序法 */ #include <stdio.h> void sort(int v[],int n) { int gap,i,j, ...
- HTML+CSS实例——漂亮的背景(一)
一.网址:http://www.csszengarden.com/?cssfile=213/213.css 二.效果 三.CSS body { background-color:#F0ECD6; ba ...
- Redis' High Availability
Redis Sentinel is a system designed to help managing Redis instances. It performs the following thre ...
- Mysql 死锁相关操作
该随笔随时记录日常工作中遇到的关于mysql的死锁相关问题 1)查看mysql当前的处理线程(connection) mysql> show processlist; 2)杀掉对应的connec ...
- Lamp下安装memcached
1.先安装 libevent,再安装 Memcached主程序 # tar xf libevent-2.0.21-stable.tar.gz # cd libevent-2.0.21-stable # ...
- [改善Java代码]使用forName动态加载类文件
动态加载(Dynamic Loading)是指在程序运行时加载需要的类库文件,对Java程序来说,一般情况下,一个类文件在启动时或首次初始化时会被加载到内存中,而反射则可以在运行时再决定是否需要加载一 ...
- poj 2289 网络流 and 二分查找
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...
- Java Concurrency - Fork/Join Framework
Normally, when you implement a simple, concurrent Java application, you implement some Runnable obje ...
- asp中utf8不会出现乱码的写法
<%@ CODEPAGE=65001 %> <% Response.CodePage=65001%> <% Response.Charset="UTF-8&qu ...