# JpaCodeTool **Repository Path**: springbootPlus/JpaCodeTool ## Basic Information - **Project Name**: JpaCodeTool - **Description**: 代码生成项目,可以根据数据库表定义自定义模板来生成代码 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 9 - **Forks**: 5 - **Created**: 2014-04-10 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 工具背景: 半手工代码生成工具,使用模板引擎velocity的特性+JDBC的相关API生成单表的CRUD代码; ================================================================================= 最大特点:可以修改模板内容自定义生成的代码,不局限于某种具体的编程语言 缺点:只能生成单表的代码,ORM中的一对多关系需要手工添加相关代码。 需要具备的知识:velocity相关的知识。 ========================配置目录说明================================================= src/main/resources/templates 代码生成模板目录 src/main/resources/jdbc.properties 配置信息文件:数据库连接的信息,代码生成目录,需要生成代码的表 src/main/resources/templates.cfg 配置文件:使用哪些代码模板,生成的文件所在的目录 src/main/resources/templates.cfg 可以使用jdbc.properties中的变量如:tableName ,javaSource等,避免重复配置 ================================================================================= MYSQL数据库表生成代码 操作步骤如下: 1.修改jdbc.properties的内容(必选) isDbClass=true dbname=market_dev #the table would translate to java code tablePrefix=t_sales_ tableName=t_sales_customer,t_sales_customer2,t_sales_customer3 tmplDir=templates1 cfgFileName=templates1.cfg 2.修改templates1.cfg内容 3.修改具体的模板,模板目录为src/main/resources/templates1 4.RUN JDBCCodeGenerator (必选) ===================================================== 从excel读取表配置信息生成代码 操作步骤如下: 1.修改jdbc.properties的内容(必选) isDbClass=false excelConfig=tableConfig.xlsx tablePrefix=t_sales_ tableName=t_sales_customer,t_sales_customer2,t_sales_customer3 tmplDir=templates0 cfgFileName=templates0.cfg 2.修改templates0.cfg内容 3.修改具体的模板,模板目录为src/main/resources/templates0 4.RUN JDBCCodeGenerator (必选) ======================== |参数名|类型|说明| |:----- |:-----|----- |isDbClass |boolean |是否数据库读取表字段配置 | |dbname |string |数据库名 | |excelConfig |string |存放表字段信息的EXCLE文件,参考tableConfig.xlsx | |tablePrefix |string |表前缀,生成代码时会去掉 | |tableName |string |待生成代码的表名, 多个使用逗号分隔 | |tmplDir |string |模板文件目录 | |cfgFileName |string |配置待生成文件列表的配置文件 |