配置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');