tableModel生成
tableModel.xml文件的存在略显多余,在生成代码的时候需要多点几个按钮,并且大多数情况都是机械式的重复劳动而已。然而从两个方面让我保留了这个中间文件的存在:
- 为了整个工具的统一,目前工具的待处理数据源均是来自文件或者前台录入,故而为了一致性需要先生成tableModel.xml;
- 方便进行微调,tableModel中的XML很多是可以进行手动调整的,方便您生成的代码不再需要人工介入。
tableModel是数据库表结构的XML描述性文件,它一般有这样的结构:
<?xml version="1.0" encoding="UTF-8" ?>
<tableModel>
<tableDefine id='AcCommonExtInfo' cnname='扩展信息' dbTableName='ac_common_ext_info'>
<column dataName='id' columnName='id' cnname='id' columnType='INT' canBeNull='false' readonly='false' isPK='true' length='10' jspTag='TEXT' dictName='' comment='id' />
<column dataName='ownerType' columnName='owner_type' cnname='归属类型' columnType='INT' canBeNull='false' readonly='false' isPK='false' length='10' jspTag='SELECT' dictName='acCommonExtInfo_ownerType_DICT' comment='归属类型:1.系统,2.项目' />
<column dataName='ownerCode' columnName='owner_code' cnname='归属码' columnType='VARCHAR' canBeNull='false' readonly='false' isPK='false' length='50' jspTag='TEXT' dictName='' comment='归属码' />
<column dataName='extKey' columnName='ext_key' cnname='扩展key' columnType='VARCHAR' canBeNull='false' readonly='false' isPK='false' length='50' jspTag='TEXT' dictName='' comment='扩展key' />
<column dataName='extValue' columnName='ext_value' cnname='扩展值' columnType='VARCHAR' canBeNull='true' readonly='false' isPK='false' length='200' jspTag='TEXT' dictName='' comment='扩展值' />
<column dataName='type' columnName='type' cnname='类型' columnType='INT' canBeNull='false' readonly='false' isPK='false' length='10' jspTag='SELECT' dictName='acCommonExtInfo_type_DICT' comment='类型:1.文本,2.json,3.xml, 4.properties, 5.开关' />
<column dataName='creator' columnName='creator' cnname='创建人' columnType='VARCHAR' canBeNull='true' readonly='false' isPK='false' length='20' jspTag='TEXT' dictName='' comment='创建人' />
<column dataName='operator' columnName='operator' cnname='修改人' columnType='VARCHAR' canBeNull='true' readonly='false' isPK='false' length='20' jspTag='TEXT' dictName='' comment='修改人' />
<column dataName='concurrentVersion' columnName='concurrent_version' cnname='并发版本号' columnType='BIGINT' canBeNull='true' readonly='false' isPK='false' length='19' jspTag='TEXT' dictName='' comment='并发版本号' />
<column dataName='dataVersion' columnName='data_version' cnname='数据版本' columnType='BIGINT' canBeNull='true' readonly='false' isPK='false' length='19' jspTag='TEXT' dictName='' comment='数据版本' />
<column dataName='status' columnName='status' cnname='状态' columnType='TINYINT' canBeNull='true' readonly='false' isPK='false' length='3' jspTag='SELECT' dictName='acCommonExtInfo_status_DICT' comment='状态:1.有效,-1.无效' />
<column dataName='created' columnName='created' cnname='创建时间' columnType='DATETIME' canBeNull='true' readonly='false' isPK='false' length='19' jspTag='DATETIME' dictName='' comment='创建时间' />
<column dataName='modified' columnName='modified' cnname='修改时间' columnType='DATETIME' canBeNull='true' readonly='false' isPK='false' length='19' jspTag='DATETIME' dictName='' comment='修改时间' />
</tableDefine>
<orderColumns>
<orderColumn orderType='desc'>id</orderColumn>
</orderColumns>
<bizFieldsMap>
<bizFields key='createTime'>created</bizFields>
<bizFields key='updateTime'>modified</bizFields>
<bizFields key='queryList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,modified</bizFields>
<bizFields key='addList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status</bizFields>
<bizFields key='updateList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status</bizFields>
<bizFields key='viewList'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,created,modified</bizFields>
<bizFields key='searchKey'>id,owner_type,type,status</bizFields>
<bizFields key='allColumn'>id,owner_type,owner_code,ext_key,ext_value,type,creator,operator,concurrent_version,data_version,status,created,modified</bizFields>
</bizFieldsMap>
<dicts>
<dict id='acCommonExtInfo_type_DICT' name='type字段的字典项'>
<option value='1' cssClass=''>文本</option>
<option value='2' cssClass=''>json</option>
<option value='3' cssClass=''>xml</option>
<option value='4' cssClass=''>properties</option>
<option value='5' cssClass=''>开关</option>
</dict>
<dict id='acCommonExtInfo_ownerType_DICT' name='owner_type字段的字典项'>
<option value='1' cssClass=''>系统</option>
<option value='2' cssClass=''>项目</option>
</dict>
<dict id='acCommonExtInfo_status_DICT' name='status字段的字典项'>
<option value='1' cssClass=''>有效</option>
<option value='-1' cssClass=''>无效</option>
</dict>
</dicts>
</tableModel>
生成说明
如下图所示,按1,2,3步骤即可完整tableModel的生成。 其中:
- 第一步为获取数据库表列表;
- 获取到列表后,勾选需要生成的数据库表;
- 点击按钮【批量生成表模型文件】 完成生成操作;
生成完毕后,会输出到:tableModel存放目录下。
【图】 tableModel生成
优化说明
如果非常必要,后续可以提供一个直接选择多个表结构然后一键完成tableModel生产和代码生成的快捷通道,当然,目前因为时间原因,这个需求并不紧迫。