CREATE DATABASE IF NOT EXISTS `gen` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; USE `gen`; CREATE TABLE `datasource_config` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `db_type` int(11) NOT NULL DEFAULT '0' COMMENT '数据库类型,1:MySql, 2:Oracle, 3:sqlserver', `driver_class` varchar(64) DEFAULT '' COMMENT '数据库驱动', `db_name` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库名称', `host` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库host', `port` int(11) NOT NULL DEFAULT '0' COMMENT '数据库端口', `username` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库用户名', `password` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库密码', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除,1:已删除,0:未删除', `package_name` varchar(100) DEFAULT NULL, `del_prefix` varchar(200) DEFAULT NULL, `group_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='数据源配置表'; CREATE TABLE `template_config` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL DEFAULT '' COMMENT '模板名称', `file_name` varchar(128) NOT NULL DEFAULT '' COMMENT '文件名称', `content` text NOT NULL COMMENT '内容', `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除,1:已删除,0:未删除', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='模板表'; INSERT INTO `template_config` (`id`, `name`, `file_name`, `content`, `is_deleted`) VALUES (1,'entity','${context.javaBeanName}.java','package ${context.packageName}.entity;\n\n#if(${table.hasDateField})\nimport java.util.Date;\n#end\n#if(${table.hasLocalDateField})\nimport java.time.LocalDate;\n#end\n#if(${table.hasLocalDateTimeField})\nimport java.time.LocalDateTime;\n#end\n#if(${table.hasBigDecimalField})\nimport java.math.BigDecimal;\n#end\n\n#if( "${table.comment}" != "" )\n/**\n * ${table.comment}\n */\n#end\npublic class ${context.javaBeanName} {\n#foreach($column in $columns)\n#if( "${column.comment}" != "" )\n /** ${column.comment} */\n#end\n private ${column.javaTypeBox} ${column.javaFieldName};\n#end\n\n#foreach(${column} in ${columns})\n public void set${column.javaFieldNameUF}(${column.javaTypeBox} ${column.javaFieldName}) {\n this.${column.javaFieldName} = ${column.javaFieldName};\n }\n \n public ${column.javaTypeBox} get${column.javaFieldNameUF}() {\n return this.${column.javaFieldName};\n }\n \n#end\n\n @Override\n public boolean equals(Object o) {\n if (this == o) { return true; }\n if (o == null || getClass() != o.getClass()) {return false;}\n ${context.javaBeanName} that = (${context.javaBeanName}) o;\n return ${pk.javaFieldName}.equals(that.${pk.javaFieldName});\n }\n\n @Override\n public int hashCode() {\n return java.util.Objects.hash(${pk.javaFieldName});\n }\n \n @Override\n public String toString() {\n return "${context.javaBeanName}{" +\n#foreach(${column} in ${columns})\n #if($velocityCount == 1)\n "${column.javaFieldName}=" + ${column.javaFieldName} +\n #else\n ",${column.javaFieldName}=\'" + ${column.javaFieldName} + "\'" + \n #end\n#end\n \'}\';\n }\n \n}',0), (2,'mybatis','${context.javaBeanName}Mapper.xml','#set($jq="$")\n\n\n\n \n #foreach($column in $columns) \n \n #end\n \n \n \n \n #foreach($column in $columns)\n #if($velocityCount > 1),#end t.${column.columnName}\n #end\n \n \n \n \n \n \n \n\n \n \n INSERT INTO ${table.tableName}\n \n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n ${column.columnName},\n #end \n #end\n \n \n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n #{${column.javaFieldName}}, \n #end \n #end\n \n \n \n \n \n INSERT INTO ${table.tableName} \n \n\n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n \n ${column.columnName},\n \n #end \n #end\n \n \n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n \n #{${column.javaFieldName}}, \n \n #end \n #end\n \n \n\n \n \n UPDATE ${table.tableName}\n \n #foreach($column in $columns) \n #if(!${column.isPk}) \n ${column.columnName}=#{${column.javaFieldName}}, \n #end \n #end\n \n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n \n \n \n \n \n UPDATE ${table.tableName}\n \n #foreach($column in $columns) \n #if(!${column.isPk}) \n \n ${column.columnName}=#{${column.javaFieldName}}, \n \n #end \n #end\n \n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n \n\n \n \n \n UPDATE ${table.tableName}\n SET is_deleted=1\n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n \n\n\n',0), (3,'dao','${context.javaBeanName}Mapper.java','package ${context.packageName}.mapper;\n\nimport java.util.List;\nimport org.apache.ibatis.annotations.Mapper;\nimport ${context.packageName}.entity.${context.javaBeanName};\n\n@Mapper\npublic interface ${context.javaBeanName}Mapper {\n\n /**\n * 查询所有记录\n *\n * @return 返回集合,没有返回空List\n */\n List<${context.javaBeanName}> listAll();\n\n\n /**\n * 根据主键查询\n *\n * @param id 主键\n * @return 返回记录,没有返回null\n */\n ${context.javaBeanName} getById(${pk.javaTypeBox} ${pk.javaFieldName});\n \n /**\n * 新增,插入所有字段\n *\n * @param ${context.javaBeanNameLF} 新增的记录\n * @return 返回影响行数\n */\n int insert(${context.javaBeanName} ${context.javaBeanNameLF});\n \n /**\n * 新增,忽略null字段\n *\n * @param ${context.javaBeanNameLF} 新增的记录\n * @return 返回影响行数\n */\n int insertIgnoreNull(${context.javaBeanName} ${context.javaBeanNameLF});\n \n /**\n * 修改,修改所有字段\n *\n * @param ${context.javaBeanNameLF} 修改的记录\n * @return 返回影响行数\n */\n int update(${context.javaBeanName} ${context.javaBeanNameLF});\n \n /**\n * 修改,忽略null字段\n *\n * @param ${context.javaBeanNameLF} 修改的记录\n * @return 返回影响行数\n */\n int updateIgnoreNull(${context.javaBeanName} ${context.javaBeanNameLF});\n \n /**\n * 删除记录\n *\n * @param ${context.javaBeanNameLF} 待删除的记录\n * @return 返回影响行数\n */\n int delete(${context.javaBeanName} ${context.javaBeanNameLF});\n \n}',0), (4,'service','${context.javaBeanName}Service','package ${context.packageName}.mapper;\n\nimport ${context.packageName}.entity.${context.javaBeanName};\nimport ${context.packageName}.mapper.${context.javaBeanName}Mapper;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\nimport java.util.List;\n\n@Service\npublic class ${context.javaBeanName}Service {\n\n @Autowired\n private ${context.javaBeanName}Mapper ${context.javaBeanNameLF}Mapper;\n\n /**\n * 查询所有记录\n *\n * @return 返回集合,没有返回空List\n */\n public List<${context.javaBeanName}> listAll() {\n return ${context.javaBeanNameLF}Mapper.listAll();\n }\n\n\n /**\n * 根据主键查询\n *\n * @param id 主键\n * @return 返回记录,没有返回null\n */\n public ${context.javaBeanName} getById(${pk.javaTypeBox} ${pk.javaFieldName}) {\n return ${context.javaBeanNameLF}Mapper.getById(${pk.javaFieldName});\n }\n \n /**\n * 新增,插入所有字段\n *\n * @param ${context.javaBeanNameLF} 新增的记录\n * @return 返回影响行数\n */\n public int insert(${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Mapper.insert(${context.javaBeanNameLF});\n }\n \n /**\n * 新增,忽略null字段\n *\n * @param ${context.javaBeanNameLF} 新增的记录\n * @return 返回影响行数\n */\n public int insertIgnoreNull(${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Mapper.insertIgnoreNull(${context.javaBeanNameLF});\n }\n \n /**\n * 修改,修改所有字段\n *\n * @param ${context.javaBeanNameLF} 修改的记录\n * @return 返回影响行数\n */\n public int update(${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Mapper.update(${context.javaBeanNameLF});\n }\n \n /**\n * 修改,忽略null字段\n *\n * @param ${context.javaBeanNameLF} 修改的记录\n * @return 返回影响行数\n */\n public int updateIgnoreNull(${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Mapper.updateIgnoreNull(${context.javaBeanNameLF});\n }\n \n /**\n * 删除记录\n *\n * @param ${context.javaBeanNameLF} 待删除的记录\n * @return 返回影响行数\n */\n public int delete(${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Mapper.delete(${context.javaBeanNameLF});\n }\n \n}',0), (5,'controller','${context.javaBeanName}Controller','package ${context.packageName}.mapper;\n\nimport java.util.List;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport ${context.packageName}.entity.${context.javaBeanName};\nimport ${context.packageName}.service.${context.javaBeanName}Service;\n\n@RestController\npublic class ${context.javaBeanName}Controller {\n\n @Autowired\n private ${context.javaBeanName}Service ${context.javaBeanNameLF}Service;\n\n /**\n * 查询所有记录\n *\n * @return 返回集合,没有返回空List\n */\n @RequestMapping("list")\n public List<${context.javaBeanName}> listAll() {\n return ${context.javaBeanNameLF}Service.listAll();\n }\n\n\n /**\n * 根据主键查询\n *\n * @param id 主键\n * @return 返回记录,没有返回null\n */\n @RequestMapping("getById")\n public ${context.javaBeanName} getById(${pk.javaTypeBox} ${pk.javaFieldName}) {\n return ${context.javaBeanNameLF}Service.getById(${pk.javaFieldName});\n }\n \n /**\n * 新增,插入所有字段\n *\n * @param ${context.javaBeanNameLF} 新增的记录\n * @return 返回影响行数\n */\n @RequestMapping("insert")\n public int insert(@RequestBody ${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Service.insert(${context.javaBeanNameLF});\n }\n \n /**\n * 新增,忽略null字段\n *\n * @param ${context.javaBeanNameLF} 新增的记录\n * @return 返回影响行数\n */\n @RequestMapping("insert")\n public int insertIgnoreNull(@RequestBody ${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Service.insertIgnoreNull(${context.javaBeanNameLF});\n }\n \n /**\n * 修改,修改所有字段\n *\n * @param ${context.javaBeanNameLF} 修改的记录\n * @return 返回影响行数\n */\n @RequestMapping("update")\n public int update(@RequestBody ${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Service.update(${context.javaBeanNameLF});\n }\n \n /**\n * 修改,忽略null字段\n *\n * @param ${context.javaBeanNameLF} 修改的记录\n * @return 返回影响行数\n */\n @RequestMapping("updateIgnoreNull")\n public int updateIgnoreNull(@RequestBody ${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Service.updateIgnoreNull(${context.javaBeanNameLF});\n }\n \n /**\n * 删除记录\n *\n * @param ${context.javaBeanNameLF} 待删除的记录\n * @return 返回影响行数\n */\n @RequestMapping("delete")\n public int delete(@RequestBody ${context.javaBeanName} ${context.javaBeanNameLF}) {\n return ${context.javaBeanNameLF}Service.delete(${context.javaBeanNameLF});\n }\n \n}',0);