每年高校迎新季都是教务管理压力最大的时期之一。传统迎新方式往往面临信息孤岛、流程繁琐、数据不同步等问题。这套基于SpringBoot+Vue3+MyBatis的迎新系统,正是为解决这些痛点而设计的现代化解决方案。
我在实际部署中发现,系统通过前后端分离架构实现了三大核心价值:
采用Vue3+Element Plus的组合主要基于:
关键配置示例(vite.config.ts):
typescript复制export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [ElementPlusResolver({ importStyle: 'css' })] // 按需加载CSS
})
],
build: {
chunkSizeWarningLimit: 1500, // 调整chunk大小警告阈值
}
})
SpringBoot 2.7.x版本的选择考量:
数据库连接池配置要点:
yaml复制spring:
datasource:
hikari:
maximum-pool-size: 20 # 根据CPU核心数×2+1计算
connection-timeout: 30000
idle-timeout: 600000
采用权重分配策略:
核心Java代码片段:
java复制public class ClassAllocation {
public List<Student> autoAllocate(List<Student> students) {
// 使用Guava的Multimap按省份分组
Multimap<String, Student> provinceMap = ArrayListMultimap.create();
students.forEach(s -> provinceMap.put(s.getProvince(), s));
// 轮询分配算法
return new RoundRobinAllocator(provinceMap).allocate();
}
}
解决的关键问题:
数据库设计技巧:
sql复制CREATE TABLE dormitory (
id BIGINT PRIMARY KEY,
building VARCHAR(10) NOT NULL,
room_number VARCHAR(6) NOT NULL,
floor TINYINT CHECK (floor BETWEEN 1 AND 12),
capacity TINYINT DEFAULT 4,
remaining TINYINT,
gender_restriction ENUM('M','F','N') DEFAULT 'N',
disabled_access BOOLEAN DEFAULT FALSE,
UNIQUE KEY (building, room_number)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
安全增强措施:
Spring Security配置示例:
java复制@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/auth/**").permitAll()
.antMatchers(HttpMethod.GET, "/api/announcements").permitAll()
.anyRequest().authenticated();
http.addFilterBefore(jwtFilter(), UsernamePasswordAuthenticationFilter.class);
return http.build();
}
}
针对入学材料上传的特别处理:
Vue组件关键代码:
vue复制<template>
<el-upload
:action="uploadUrl"
:before-upload="handleBeforeUpload"
:on-success="handleSuccess"
:data="extraParams"
:multiple="false"
:limit="5"
:file-list="fileList">
<el-button type="primary">点击上传</el-button>
</el-upload>
</template>
<script setup>
const handleBeforeUpload = (file) => {
const isLt10M = file.size / 1024 / 1024 < 10;
if (!isLt10M) {
ElMessage.error('文件大小不能超过10MB');
return false;
}
return true;
}
</script>
慢查询日志分析后发现的问题:
优化方案:
sql复制ALTER TABLE student ADD INDEX idx_college_major (college_id, major_id);
java复制@Configuration
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.setCaffeine(Caffeine.newBuilder()
.initialCapacity(100)
.maximumSize(1000)
.expireAfterWrite(10, TimeUnit.MINUTES));
return cacheManager;
}
}
通过Chrome Lighthouse检测发现:
实施改进:
nginx复制gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 1024;
bash复制# 使用cwebp批量转换
find ./src/assets -name '*.jpg' -exec cwebp -q 80 {} -o {}.webp \;
推荐服务器配置:
Docker-compose编排示例:
yaml复制version: '3'
services:
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
volumes:
- ./mysql-data:/var/lib/mysql
ports:
- "3306:3306"
backend:
build: ./backend
ports:
- "8080:8080"
depends_on:
- mysql
必备监控指标:
Prometheus配置片段:
yaml复制scrape_configs:
- job_name: 'springboot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['backend:8080']
- job_name: 'mysql'
static_configs:
- targets: ['mysqld-exporter:9104']
开发中遇到的典型问题:
最终方案:
nginx复制location /api/ {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
proxy_pass http://backend:8080;
}
初期实现方式:
优化后方案:
xml复制<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO student (id, name, college_id) VALUES
<foreach collection="list" item="item" separator=",">
(#{item.id}, #{item.name}, #{item.collegeId})
</foreach>
</insert>
properties复制spring.datasource.url=jdbc:mysql://localhost:3306/welcome?rewriteBatchedStatements=true
优化后500条数据仅需1.7秒,性能提升16倍。这个案例让我深刻认识到数据库配置参数的重要性