mysql.sql 9.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. CREATE DATABASE IF NOT EXISTS `generator1` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  2. USE `generator1`;
  3. CREATE TABLE `datasource_config` (
  4. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  5. `db_type` int(11) NOT NULL DEFAULT '0' COMMENT '数据库类型,0:MySql, 1:Oracle,2:sqlserver',
  6. `driver_class` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库驱动',
  7. `db_name` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库名称',
  8. `host` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库host',
  9. `port` int(11) NOT NULL DEFAULT '0' COMMENT '数据库端口',
  10. `username` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库用户名',
  11. `password` varchar(64) NOT NULL DEFAULT '' COMMENT '数据库密码',
  12. `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除,1:已删除,0:未删除',
  13. PRIMARY KEY (`id`)
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='数据源配置表';
  15. CREATE TABLE `template_config` (
  16. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  17. `name` varchar(64) NOT NULL DEFAULT '' COMMENT '模板名称',
  18. `file_name` varchar(128) NOT NULL DEFAULT '' COMMENT '文件名称',
  19. `content` text NOT NULL COMMENT '内容',
  20. `is_deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除,1:已删除,0:未删除',
  21. PRIMARY KEY (`id`)
  22. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='模板表';
  23. INSERT INTO `template_config` (`id`, `name`, `file_name`, `content`, `is_deleted`) VALUES
  24. (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),
  25. (2,'mybatis','${context.javaBeanName}Mapper.xml','#set($jq="$")\n<?xml version="1.0" encoding="UTF-8" ?>\n<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >\n<mapper namespace="${context.packageName}.mapper.${context.javaBeanName}Mapper">\n <resultMap id="BaseResultMap" type="${context.packageName}.entity.${context.javaBeanName}">\n #foreach($column in $columns) \n <result column="${column.columnName}" property="${column.javaFieldName}" jdbcType="${column.mybatisJdbcType}" />\n #end\n </resultMap> \n \n <!-- 表字段 -->\n <sql id="baseColumns">\n #foreach($column in $columns)\n #if($velocityCount > 1),#end t.${column.columnName}\n #end\n </sql> \n \n <!-- 查询全部 -->\n <select id="listAll" resultMap="BaseResultMap">\n SELECT \n <include refid="baseColumns" />\n FROM ${table.tableName} t\n </select>\n \n <!-- 根据主键获取单条记录 -->\n <select id="getById" resultMap="BaseResultMap" parameterType="${pk.javaTypeBox}">\n SELECT \n <include refid="baseColumns" />\n FROM ${table.tableName} t\n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n </select>\n\n <!-- 插入全部字段 -->\n <insert id="insert" parameterType="${context.packageName}.entity.${context.javaBeanName}"\n keyProperty="${context.javaPkName}" keyColumn="${context.pkName}" useGeneratedKeys="true"\n >\n INSERT INTO ${table.tableName}\n <trim prefix="(" suffix=")" suffixOverrides=","> \n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n ${column.columnName},\n #end \n #end\n </trim>\n <trim prefix="VALUES (" suffix=")" suffixOverrides=","> \n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n #{${column.javaFieldName}}, \n #end \n #end\n </trim>\n </insert>\n \n <!-- 插入不为NULL的字段 -->\n <insert id="insertIgnoreNull" parameterType="${context.packageName}.entity.${context.javaBeanName}"\n keyProperty="${pk.javaFieldName}" keyColumn="${context.pkName}" useGeneratedKeys="true"\n >\n INSERT INTO ${table.tableName} \n <trim prefix="(" suffix=")" suffixOverrides=","> \n\n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n <if test="${column.javaFieldName} != null">\n ${column.columnName},\n </if>\n #end \n #end\n </trim>\n <trim prefix="VALUES (" suffix=")" suffixOverrides=","> \n #foreach($column in $columns) \n #if(!${column.isIdentityPk}) \n <if test="${column.javaFieldName} != null" >\n #{${column.javaFieldName}}, \n </if>\n #end \n #end\n </trim>\n </insert>\n\n <!-- 更新,更新全部字段 -->\n <update id="update" parameterType="${context.packageName}.entity.${context.javaBeanName}">\n UPDATE ${table.tableName}\n <set> \n #foreach($column in $columns) \n #if(!${column.isPk}) \n ${column.columnName}=#{${column.javaFieldName}}, \n #end \n #end\n </set> \n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n </update> \n \n \n <!-- 更新不为NULL的字段 -->\n <update id="updateIgnoreNull" parameterType="${context.packageName}.entity.${context.javaBeanName}">\n UPDATE ${table.tableName}\n <set>\n #foreach($column in $columns) \n #if(!${column.isPk}) \n <if test="${column.javaFieldName} != null" >\n ${column.columnName}=#{${column.javaFieldName}}, \n </if>\n #end \n #end\n </set>\n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n </update>\n\n \n <!-- 根据主键删除记录 -->\n <delete id="delete" parameterType="${context.packageName}.entity.${context.javaBeanName}">\n UPDATE ${table.tableName}\n SET is_deleted=1\n WHERE ${pk.columnName} = #{${pk.javaFieldName}}\n </delete>\n\n\n</mapper>',0),
  26. (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);