-
-
Notifications
You must be signed in to change notification settings - Fork 727
FAQ
支持三种表模式,通过table.mode指定。 未指定mode属性情况下,如果index为空或者主键个数为1,则为map表,否则为list表。
- map表。 即最常见的 单主键 key-value表。
- list表。 列表表。支持0-n个主键。可以有任意多个主键。 list又细分为3种
- 无主键模式
- 联合多主键模式
- 独立多主键模式
- singleton单例表
table的index字段指定主键列表。
普通表支持主键概念,list表支持0到多个主键,单例表无主键 。 未指定mode和index的情况下,自动为mode=map模式,并记录bean的第一个字段作为主键。
假设 TbTest表的记录为Test类型,你想用Test的my_index字段作为key,则:
- 如果在xml里定义表,则在table的index属性中指定主键字段名,如下:
<table name="TbTest" value="Test" index="my_index"/>- 如果在 table.xlsx里定义表,则在index列指定主键名,如下
| ## | full_name | value_type | define_from_excel | input | index | ... |
|---|---|---|---|---|---|---|
| TbTest | Test | true | equip.xlsx | my_index |
支持。 table mode=list时,支持联合多主键模式和独立多主键模式。
有时候只想得到一个记录列表,无主键。mode="list"并且index为空,表示无主键表。
定义表
<table name="TbNotKeyList" value="NotKeyList" mode="list" input="not_key_list.xlsx"/>示例数据表
| ## | x | y | z | num |
|---|---|---|---|---|
| ##type | int | long | string | int |
| 1 | 1 | aaa | 123 | |
| 1 | 1 | bbb | 124 | |
| 1 | 2 | aaa | 134 | |
| 2 | 1 | aaa | 124 | |
| 5 | 6 | xxx | 898 |
多个key构成联合唯一主键。使用"+"分割key,表示联合关系。
定义表
<table name="TbUnionMultiKey" value="UnionMultiKey" index="key1+key2+key3" input="union_multi_key.xlsx"/>示例数据表
| ## | key1 | key2 | key3 | num |
|---|---|---|---|---|
| ##type | int | long | string | int |
| 1 | 1 | aaa | 123 | |
| 1 | 1 | bbb | 124 | |
| 1 | 2 | aaa | 134 | |
| 2 | 1 | aaa | 124 | |
| 5 | 6 | xxx | 898 |
多个key,各自独立唯一索引。与联合索引写法区别在于使用 ","来划分key,表示独立关系。
定义表
<table name="TbMultiKey" value="MultiKey" index="key1,key2,key3" input="multi_key.xlsx"/>示例数据表
| ## | key1 | key2 | key3 | num |
|---|---|---|---|---|
| ##type | int | long | string | int |
| 1 | 2 | aaa | 123 | |
| 2 | 4 | bbb | 124 | |
| 3 | 6 | ccc | 134 | |
| 4 | 8 | ddd | 124 | |
| 5 | 1 | eee | 898 |
有哪些分组,是在__root__.xml中定义的,可以完全自由配置,如下:
<group name="c" default="1"/> client
<group name="s" default="1"/> server
<group name="e" default="1"/> editor
<service name="server" manager="Tables" group="s"/>
<service name="client" manager="Tables" group="c"/>
<service name="all" manager="Tables" group="c,s,e"/>group定义了一个分组类型。 default表明,table未指定分组的情况下,是否默认属于此分组。
service配置了某个service需要导出哪些分组。 service的name属性即 Luban.Client命令行参数里的 -s 参数。 例如,指定 -s all后,导出c,s,e分组的配置。
目前支持两种粒度的分组导出:table级别和bean字段级别。table定义和 bean的field定义都支持group属性。
- table 级别导出 table的group属性如果不指定,则默认对所有group.default=1的分组导出,如果指定,则只对指定分组导出。可以有多个分组。
xml格式定义如下
<table name="TbClothDisplay" value="ClothDisplay" group="c" input="test/cloth.xlsx"/> 此表只属于c分组
<table name="TbItem" value="Item" group="c,s" input="test/item.xlsx"/> 此表属于c,s分组
<table name="TbWidget" value="Window" group="e" input="test/widget.xlsx"/> 此表只属于e分组xlsx格式定义如下
| ## | full_name | value_type | input | group | ... |
|---|---|---|---|---|---|
| TbClothDisplay | ClothDisplay | cloth/cloth.xlsx | c | ||
| TbItem | Item | item/item.xlsx | c,s | ||
| TbWidget | Widget | ui/widget.xlsx | e |
Luban.Client使用 -s client 参数时,只导出TbDemoGroup_C和TbDemoGroup_CS表,而TbDemoGroup_E表不会导出。
- bean的field级别导出
导出配置时,bean中某个field根据分组导出。
xml定义格式如下:
<bean name="DemoGroup">
<var name="id" type="int"/>
<var name="x1" type="int"/> 默认属于所有分组c,s,e
<var name="x2" type="int" group="c"/>属于 c 分组
<var name="x3" type="int" group="s"/>属于s分组
<var name="x4" type="int" group="c,s"/>属于c,s分组
</bean>如果在 __bean__.xlsx 中定义bean,格式如下
| ## | full_name | sep | comment | field.name | fields.type | field.group | ... |
|---|---|---|---|---|---|---|---|
| DemoGroup | id | int | |||||
| x1 | int | ||||||
| x2 | int | c | |||||
| x3 | int | s | |||||
| x4 | int | c,s |
如果直接在数据表里定义的bean结构,格式如下
| ## | id | x1 | x2&group=c | x3&group=s | x4&group=c,s |
|---|---|---|---|---|---|
| ##type | int | int | int | int | int |
| 1 | 2 | 2 | 2 | 2 |
当 -s client 时, id、x1、x2、x4字段导出。 当 -s server 时, id、x1、x3、x4字段导出。
- excel族。 csv、xls、xlm、xlsx、xlsm 等等。 csv支持各种编码,luban会智能猜测它的编码,无论你用gbk还是utf-8或者其他编码,都能正确处理。
- json
- xml
- lua
- yaml
table的input属性(也即数据源)支持以下几种组织形式,允许开发者根据情况灵活组织配置文件结构:
- 来自某个excel文件的所有单元薄
- 来自某个excel文件的指定单元薄
- 来自json、xml、lua、yaml文件
- 来自json、xml、lua、yaml子字段 (如root.a.b)
- 来自目录。目录树下所有文件(包含递归子目录)都会被当作数据源读入,每个文件(excel族例外)对应一个记录
- 以上的随意组合