zoukankan      html  css  js  c++  java
  • SpringBoot中配置起动时的数据库初始化脚本

    配置application.yml

    连接字符串

    spring:
      datasource:
        platform: mysql
        url: jdbc:mysql://localhost:3306/gov_admin?useUnicode=true&characterEncoding=UTF-8
        username: root
        password: 111111
        driver-class-name: com.mysql.jdbc.Driver
        sql-script-encoding: utf-8
        schema: classpath:schema.sql
        data: classpath:data.sql
        continue-on-error: true
        initialization-mode: always
        type: com.alibaba.druid.pool.DruidDataSource
    

    初始化数据

    spring.datasource.schema=classpath:schema.sql
    spring.datasource.data=classpath:data.sql
    spring.datasource.sql-script-encoding=utf-8
    spring.datasource.initialization-mode=ALWAYS
    

    因为SpringBoot在启动时,只有检测到spring.datasource.initialization-mode=ALWAYS配置,后再检测spring.datasource.schema之后,且配置的sql角本命令不为空,才会去执行schema和spring.datasource.data。因此需要在scheme.sql中随便写一句sql语句

    创建schema.sql脚本

    -- 系统组织表
    CREATE TABLE IF NOT EXISTS `organization` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT,
      `address` varchar(255) DEFAULT NULL,
      `coords` varchar(255) DEFAULT NULL,
      `email` varchar(255) DEFAULT NULL,
      `fax` varchar(255) DEFAULT NULL,
      `key_values` varchar(255) DEFAULT NULL,
      `level` int(11) DEFAULT NULL,
      `name` varchar(255) DEFAULT NULL,
      `org_code` varchar(255) DEFAULT NULL,
      `parent_id` bigint(20) DEFAULT NULL,
      `phone_number` varchar(255) DEFAULT NULL,
      `pinyin` varchar(255) DEFAULT NULL,
      `region_id` bigint(20) DEFAULT NULL,
      `sort` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    

    创建date.sql脚本

    -- 初始化系统组织
    INSERT IGNORE INTO `organization` (`id`, `org_code`, `name`, `pinyin`, `parent_id`, `phone_number`, `fax`, `level`, `sort`, `region_id`, `address`, `key_values`) VALUES
        ('1', 'ce6019d8', '系统组织', NULL, '0', NULL, NULL, '1', '1', NULL, NULL, '{}');
    
    -- 初始化系统管理员角色
    INSERT IGNORE INTO `sys_role` (`id`, `name`, `type`, `value`, `organization_id`) VALUES
        ('1', '管理员', '0', NULL, '1');
    
    -- 初始化系统菜单数据
    INSERT IGNORE INTO `sys_resource` (`id`, `description`, `icon`, `name`, `parent_id`, `res`, `sort`, `type`, `levels`,`organization_id`, `visible`) VALUES
        ('1', '用户', 'glyphicon glyphicon-user icon', '用户', NULL, NULL, '1', '0', '1', '1', '1'),
        ('2', '账户管理', NULL, '账户管理', '1', 'app.sysuser', '1', '0', '2', '1', '1'),
        ('3', '角色管理', NULL, '角色管理', '1', 'app.sysrole', '2', '0', '2', '1', '1'),
        ('4', '组织管理', NULL, '组织管理', '1', 'app.organization', '3', '0', '2', '1', '1'),
        ('5', '日志', 'glyphicon glyphicon-edit icon', '日志', NULL, NULL, '8', '0', '1', '1', '1'),
        ('6', '浏览日志', NULL, '浏览日志', '5', 'app.browseLog', '1', '0', '2', '1', '1'),
        ('7', '操作日志', NULL, '操作日志', '5', 'app.operationLog', '2', '0', '2', '1', '1'),
        ('8', '设置', 'icon icon-settings icon', '设置', NULL, NULL, '10', '0', '1', '1', '1'),
        ('9', '全局设置', NULL, '全局设置', '8', 'app.globalConfig', '1', '0', '2', '1', '1'),
        ('10', '数据字典', NULL, '数据字典', '8', 'app.dicType', '2', '0', '2', '1', '1'),
        ('11', '局域管理', NULL, '局域管理', '8', 'app.administrativeArea', '3', '0', '2', '1', '1'),
        ('12', '菜单管理', NULL, '菜单管理', '8', 'app.sysResource', '4', '0', '2', '1', '1');
    
    认真可以把事情做对,而用心却可以做到完美
  • 相关阅读:
    QT两个字符串转化函数,避免文字乱码。
    QT隐藏工具栏上的右键菜单
    QT线程初次使用。遇到的问题。
    QTableView根据标题文字和表格文字自适应宽度
    void QTableView::setColumnWidth ( int column, int width),隐藏列不起作用
    在VS2010中去掉ipch和sdf文件方法
    QT的一个奇怪问题,设置了Qt::Tool后,点击弹出对话框的确定取消按钮,程序直接退出
    上传图片并显示缩略图的最简单方法(c#)
    总结一下散乱的开发点滴(2) (高手勿入)
    在global里捕获黄页并写入异常日志库
  • 原文地址:https://www.cnblogs.com/fangh816/p/13294246.html
Copyright © 2011-2022 走看看