ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
### 答 > OFBiz系统提供了一个专用于系统维护的网页版工具模块[webtools], 这里有很多工具, 方便系统管理人员从容的在线管理我们的系统. > 接下来我将详细介绍一下, [webtools]模块提供的数据导入功能 > #### 登录[webtools]模块 > - 运行项目等待启动成功. > - 浏览器访问网址: https://localhost:8443/webtools > - 使用[admin]账户, 密码[ofbiz]登录这个模块. > - 在登录的主界面中找到**Entity XML Tools(实体XML工具)** 功能区. > - 点击**XML Data Import(XML数据导入)** . (https://localhost:8443/webtools/control/EntityImport) > - 这里提供了多种导入数据的方案: > - XML数据文件的网址方式. (如: http://localhost/DemoData.xml) > - XML数据文件在项目运行本机的磁盘文件. (如: /home/user1/data/DemoData.xml) > - 文本域大输入框, 直接粘贴XML数据 > 下面我们逐一介绍一下用法 #### XML数据文件的网址方式 > 假定待导入的文件网址是[http://localhost/DemoData.xml] > 如下图操作 > ![EntityImport1](https://box.kancloud.cn/d1c92560cd30a4baf91477db4176fcd6_924x432.png =200x100) > 1. 在**Absolute Filename or URL(绝对文件名或网址)** 输入: http://localhost/DemoData.xml > 2. 勾选**Is URL?(是网址?)** > 3. 点击**Import File(导入文件)** 提交导入操作. #### XML数据文件在项目运行本机的磁盘文件 > 假定待导入的文件网址是[/home/user1/data/DemoData.xml] > 如下图操作 > ![EntityImport2](https://box.kancloud.cn/b4cee3e99738f9b50ad4606f6c0adc25_912x428.png =200x100) > 1. 在**Absolute Filename or URL(绝对文件名或网址)** 输入: /home/user1/data/DemoData.xml > 2. 点击**Import File(导入文件)** 提交导入操作. #### 文本域大输入框, 直接粘贴XML数据 > 假定待导入的[DemoData.xml]文件内容如下: > ~~~ > <?xml version="1.0" encoding="UTF-8"?> > <entity-engine-xml> > <SecurityPermission description="View operations in the NewLearn Component." permissionId="NEWLEARN_VIEW"/> > </entity-engine-xml> > ~~~ > 如下图操作 > ![EntityImport3](https://box.kancloud.cn/e8ce4b09cd4bb390083e82451ed1ca8a_1520x250.png) > 1. 在文本域内粘贴待导入的数据: ` <SecurityPermission description="View operations in the NewLearn Component." permissionId="NEWLEARN_VIEW"/> ` > 2. 点击**Import Text(导入文本)** 提交导入操作. >[warning] 注意: > 1. 如上图, 文本域内数据的根标签必须是[entity-engine-xml] > 2. Data数据的导入是有顺序要求的, 因为表数据有外键依赖, 一般规律是: > 1). TypeData > 2). SecurityData: [SecurityPermissionSeedData] 和 [SecurityGroupDemoData] > 3). DemoData > 4). 其他Data #### 导入整个目录下的数据 > OFBiz还提供了一种方式, 这种方式可以导入一个目录下的多个文件. > 这是一个特殊导入方式功能, 所以和前面讲的导入方式不在一起. > 我们访问: **XML Data Import Dir(XML数据导入目录)**. (https://localhost:8443/webtools/control/EntityImportDir) > > 假定待导入的文件网址是[/home/user1/data] > 如下图操作 > ![EntityImport4](https://box.kancloud.cn/dfa2c80618f066f708e9c418eb52fa1b_918x424.png =200x100) > 1. 在**Absolute directory path(目录绝对路径)** 输入: /home/user1/data > 2. 点击**Import File(导入文件)** 提交导入操作. #### 所有导入功能都依赖一个服务: entityImport > 这里我们稍微了解下这个服务的传入参数的定义 ~~~ <!-- entityImport 服务: org.ofbiz.webtools.WebToolsServices.entityImport --> <permission-service service-name="entityMaintPermCheck" main-action="VIEW"/> <!-- 检测当前用户是否有查看权限 --> <attribute name="filename" type="String" mode="IN" optional="true" allow-html="any"/> <!-- 绝对文件名或网址 --> <attribute name="fmfilename" type="String" mode="IN" optional="true" allow-html="any"/> <!-- 用于过滤数据的FreeMarker模版文件的绝对文件名[可选] --> <attribute name="fulltext" type="String" mode="IN" optional="true" allow-html="any"/> <!-- 完整的XML文档(根标签: entity-engine-xml) --> <attribute name="isUrl" type="String" mode="IN" optional="true"/> <!-- 是网址吗 --> <attribute name="mostlyInserts" type="String" mode="IN" optional="true"/> <!-- 大部分是插入吗 --> <attribute name="maintainTimeStamps" type="String" mode="IN" optional="true"/> <!-- 维护时间戳吗 --> <attribute name="createDummyFks" type="String" mode="IN" optional="true"/> <!-- 新建伪外键 --> <attribute name="checkDataOnly" type="String" mode="IN" optional="true"/> <!-- 仅检查数据[不修改数据库] --> <attribute name="txTimeout" type="Integer" mode="IN" optional="true"/> <!-- TX超时秒数[对每个实体] --> <attribute name="messages" type="List" mode="OUT" optional="false"/> <!-- 服务处理结果 --> ~~~ > 在这个服务[entityImport]里调用了一个核心服务: parseEntityXmlFile > 我们再看看这个服务[parseEntityXmlFile]的传入参数定义 ~~~ <!-- 上述服务内部调用 parseEntityXmlFile 服务: org.ofbiz.webtools.WebToolsServices.parseEntityXmlFile --> <permission-service service-name="entityMaintPermCheck" main-action="VIEW"/> <!-- 检测当前用户是否有查看权限 --> <attribute name="url" type="java.net.URL" mode="IN" optional="true"/> <!-- 网址 --> <attribute name="xmltext" type="String" mode="IN" optional="true" allow-html="any"/> <!-- 完整的XML文档(根标签: entity-engine-xml) --> <attribute name="mostlyInserts" type="String" mode="IN" optional="true"/> <!-- 大部分是插入吗 --> <attribute name="maintainTimeStamps" type="String" mode="IN" optional="true"/> <!-- 维护时间戳吗 --> <attribute name="txTimeout" type="Integer" mode="IN" optional="true"/> <!-- TX超时秒数[对每个实体] --> <attribute name="createDummyFks" type="String" mode="IN" optional="true"/> <!-- 新建伪外键 --> <attribute name="checkDataOnly" type="String" mode="IN" optional="true"/> <!-- 仅检查数据[不修改数据库] --> <attribute name="rowProcessed" type="Long" mode="OUT" optional="false"/> <!-- 数据处理成功数 --> ~~~