mysql.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. CREATE DATABASE IF NOT EXISTS `gen` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  2. USE `gen`;
  3. CREATE TABLE `datasource_config` (
  4. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  5. `db_type` int(11) NOT NULL DEFAULT '0' COMMENT '数据库类型,1:MySql, 2:Oracle, 3: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),
  27. (4,'vue','${context.javaBeanNameLF}.vue','#set($jq="$")
  28. <template>
  29. <div class="app-container">
  30. <el-form :inline="true" :model="searchFormData" class="demo-form-inline" size="mini">
  31. #foreach($column in $columns)
  32. #if(!${column.isPk})
  33. <el-form-item
  34. #if( "${column.comment}" != "" )
  35. label="${column.comment}"
  36. #else
  37. label="${column.javaFieldName}"
  38. #end
  39. >
  40. <el-input v-model="searchFormData.${column.javaFieldName}" :clearable="true" placeholder="${column.comment}" style="width: 250px;" />
  41. </el-form-item>
  42. #end
  43. #end
  44. <el-form-item>
  45. <el-button type="primary" icon="el-icon-search" @click="loadTable">查询</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-button type="primary" size="mini" icon="el-icon-plus" style="margin-bottom: 10px;" @click="onAdd">新增</el-button>
  49. <el-table
  50. :data="pageInfo.rows"
  51. border
  52. highlight-current-row
  53. >
  54. #foreach($column in $columns)
  55. <el-table-column
  56. prop="${column.javaFieldName}"
  57. #if( "${column.comment}" != "" )
  58. label="${column.comment}"
  59. #else
  60. label="${column.javaFieldName}"
  61. #end
  62. />
  63. #end
  64. <el-table-column>
  65. <template slot-scope="scope">
  66. <el-button type="text" size="mini" @click="onTableUpdate(scope.row)">修改</el-button>
  67. <el-button type="text" size="mini" @click="onTableDelete(scope.row)">删除</el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <el-pagination
  72. background
  73. style="margin-top: 5px"
  74. :current-page="searchFormData.pageIndex"
  75. :page-size="searchFormData.pageSize"
  76. :page-sizes="[5, 10, 20, 40]"
  77. :total="pageInfo.total"
  78. layout="total, sizes, prev, pager, next"
  79. @size-change="onSizeChange"
  80. @current-change="onPageIndexChange"
  81. />
  82. <!--dialog-->
  83. <el-dialog
  84. :title="dialogTitle"
  85. :visible.sync="dialogVisible"
  86. :close-on-click-modal="false"
  87. @close="resetForm(''dialogForm'')"
  88. >
  89. <el-form
  90. ref="dialogForm"
  91. :rules="dialogFormRules"
  92. :model="dialogFormData"
  93. label-width="120px"
  94. size="mini"
  95. >
  96. #foreach($column in $columns)
  97. #if(!${column.isPk})
  98. <el-form-item
  99. prop="${column.javaFieldName}"
  100. #if( "${column.comment}" != "" )
  101. label="${column.comment}"
  102. #else
  103. label="${column.javaFieldName}"
  104. #end
  105. >
  106. <el-input v-model="dialogFormData.${column.javaFieldName}" />
  107. </el-form-item>
  108. #end
  109. #end
  110. </el-form>
  111. <div slot="footer" class="dialog-footer">
  112. <el-button @click="dialogVisible = false">取 消</el-button>
  113. <el-button type="primary" @click="onDialogSave">保 存</el-button>
  114. </div>
  115. </el-dialog>
  116. </div>
  117. </template>
  118. <script>
  119. import axios from ''axios''
  120. // 创建axios实例
  121. const client = axios.create({
  122. baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
  123. timeout: 60000 // 请求超时时间,60秒
  124. })
  125. export default {
  126. data() {
  127. return {
  128. searchFormData: {
  129. #foreach($column in $columns)
  130. ${column.javaFieldName}: '''',
  131. #end
  132. pageIndex: 1,
  133. pageSize: 10
  134. },
  135. pageInfo: {
  136. rows: [],
  137. total: 0
  138. },
  139. dialogVisible: false,
  140. dialogTitle: '''',
  141. dialogFormData: {
  142. #foreach($column in $columns)
  143. #if($velocityCount > 1),#end ${column.javaFieldName}: ''''
  144. #end
  145. },
  146. dialogFormRules: {
  147. #foreach($column in $columns)
  148. #if($velocityCount > 1),#end ${column.javaFieldName}: [
  149. { required: true, message: ''不能为空'', trigger: ''blur'' }
  150. ]
  151. #end
  152. }
  153. }
  154. },
  155. created() {
  156. this.loadTable()
  157. },
  158. methods: {
  159. loadTable() {
  160. this.post(''/${context.javaBeanNameLF}/list'', this.searchFormData, resp => {
  161. this.pageInfo.rows = resp.data
  162. })
  163. },
  164. onTableUpdate(row) {
  165. this.dialogTitle = ''修改''
  166. this.dialogVisible = true
  167. this.${jq}nextTick(() => {
  168. Object.assign(this.dialogFormData, row)
  169. })
  170. },
  171. onTableDelete(row) {
  172. this.confirm(`确认要删除该记录吗?`, function(done) {
  173. const data = {
  174. ${pk.javaFieldName}: row.${pk.javaFieldName}
  175. }
  176. this.post(''/${context.javaBeanNameLF}/del'', data, () => {
  177. done()
  178. this.tip(''删除成功'')
  179. this.loadTable()
  180. })
  181. })
  182. },
  183. onDialogSave() {
  184. this.${jq}refs.dialogForm.validate((valid) => {
  185. if (valid) {
  186. const uri = this.dialogFormData.${pk.javaFieldName} ? ''/${context.javaBeanNameLF}/update'' : ''/${context.javaBeanNameLF}/add''
  187. this.post(uri, this.dialogFormData, () => {
  188. this.dialogVisible = false
  189. this.loadTable()
  190. })
  191. }
  192. })
  193. },
  194. onSizeChange(size) {
  195. this.searchFormData.pageSize = size
  196. this.loadTable()
  197. },
  198. onAdd() {
  199. this.dialogTitle = ''新增''
  200. this.dialogVisible = true
  201. this.dialogFormData.${pk.javaFieldName} = 0
  202. },
  203. onPageIndexChange(pageIndex) {
  204. this.searchFormData.pageIndex = pageIndex
  205. this.loadTable()
  206. },
  207. /**
  208. * 请求接口
  209. * @param uri uri
  210. * @param data 请求数据
  211. * @param callback 成功时回调
  212. * @param errorCallback 错误时回调
  213. */
  214. post(uri, data, callback, errorCallback) {
  215. const that = this
  216. client.post(uri, data).then(function(response) {
  217. const resp = response.data
  218. const code = resp.code
  219. if (code === ''0'') { // 成功
  220. callback && callback.call(that, resp)
  221. } else {
  222. that.${jq}message.error(resp.msg)
  223. }
  224. }).catch(function(error) {
  225. console.error(error)
  226. errorCallback && errorCallback(error)
  227. that.${jq}message.error(error.message)
  228. })
  229. }
  230. }
  231. }
  232. </script>',0);