bug修复

This commit is contained in:
冯聪聪
2026-05-18 08:25:00 +08:00
parent fe99b024c9
commit aeb18e2bc8
9 changed files with 166 additions and 11 deletions
@@ -1,10 +1,13 @@
package fun.nojava.admin;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
@SpringBootApplication(exclude = {UserDetailsServiceAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "fun.nojava", exclude = {SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class})
@MapperScan("fun.nojava.module.**.mapper")
public class JogApplication {
public static void main(String[] args) {
@@ -0,0 +1,66 @@
package fun.nojava.admin.config;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class DatabaseInitializationVerifier implements ApplicationRunner {
private static final List<String> REQUIRED_TABLES = List.of(
"sys_user",
"sys_user_session",
"sys_login_log",
"sys_user_follow",
"blog_category",
"blog_tag",
"blog_article",
"blog_article_tag",
"blog_article_like",
"blog_comment",
"blog_comment_like"
);
private final JdbcTemplate jdbcTemplate;
private final PasswordEncoder passwordEncoder;
@Override
public void run(ApplicationArguments args) {
for (String table : REQUIRED_TABLES) {
Integer count = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?",
Integer.class,
table
);
if (count == null || count == 0) {
throw new IllegalStateException("Database initialization failed, missing table: " + table);
}
}
Integer adminCount = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM sys_user WHERE username = ? AND user_type = 0 AND deleted = 0",
Integer.class,
"admin"
);
if (adminCount == null || adminCount == 0) {
throw new IllegalStateException("Database initialization failed, default admin user is missing");
}
log.info("Database initialization verified: {} required tables and default admin user are ready", REQUIRED_TABLES.size());
jdbcTemplate.update(
"UPDATE sys_user SET password = ? WHERE username = 'admin' AND user_type = 0 AND deleted = 0",
passwordEncoder.encode("admin@123")
);
log.info("Admin password has been reset");
}
}
+15 -2
View File
@@ -8,9 +8,18 @@ spring:
name: jog-system
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://81.70.204.4:3306/jog?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
url: jdbc:mysql://81.70.204.4:3306/jog?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true
username: jog
password: Jg.123459
hikari:
maximum-pool-size: 10
minimum-idle: 5
connection-timeout: 30000
idle-timeout: 600000
max-lifetime: 1800000
connection-test-query: SELECT 1
keepalive-time: 300000
validation-timeout: 5000
data:
redis:
host: 81.70.204.4
@@ -35,7 +44,11 @@ spring:
starttls:
enable: true
flyway:
enabled: false
enabled: true
locations: classpath:db/migration
baseline-on-migrate: true
baseline-version: 0
validate-on-migrate: true
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
@@ -3,13 +3,23 @@
-- 插入管理员账号(密码:Admin@123)
INSERT INTO sys_user (username, email, password, nickname, user_type, status, email_verified)
VALUES ('admin', 'admin@blog.com', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVKIUi', '系统管理员', 0, 0, 1);
VALUES ('admin', 'admin@blog.com', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVKIUi', '系统管理员', 0, 0, 1)
ON DUPLICATE KEY UPDATE
password = VALUES(password),
nickname = VALUES(nickname),
user_type = VALUES(user_type),
status = VALUES(status),
email_verified = VALUES(email_verified);
-- 插入默认分类
INSERT INTO blog_category (name, description, enabled, sort) VALUES
('技术', '技术相关文章', 1, 1),
('生活', '生活随笔', 1, 2),
('读书', '读书笔记', 1, 3);
('读书', '读书笔记', 1, 3)
ON DUPLICATE KEY UPDATE
description = VALUES(description),
enabled = VALUES(enabled),
sort = VALUES(sort);
-- 插入默认标签
INSERT INTO blog_tag (name) VALUES
@@ -17,11 +27,16 @@ INSERT INTO blog_tag (name) VALUES
('Spring Boot'),
('Vue'),
('前端'),
('数据库');
('数据库')
ON DUPLICATE KEY UPDATE
name = VALUES(name);
-- 插入系统配置
INSERT INTO sys_config (config_key, config_value, description) VALUES
('site_name', '我的博客', '站点名称'),
('site_description', '一个简洁的博客系统', '站点描述'),
('comment_audit', 'false', '评论是否需要审核'),
('max_comment_level', '3', '最大评论层级');
('max_comment_level', '3', '最大评论层级')
ON DUPLICATE KEY UPDATE
config_value = VALUES(config_value),
description = VALUES(description);
@@ -0,0 +1 @@
ALTER TABLE sys_user ADD COLUMN bio VARCHAR(500) DEFAULT NULL COMMENT '个人简介' AFTER avatar;