车辆管理系统作为现代企业运营的刚需工具,在物流运输、汽车租赁、机关单位等场景中扮演着重要角色。这个基于SpringBoot+Vue的全栈项目,不仅适合作为Java Web方向的毕业设计选题,更是一个具备实际商用价值的解决方案。我在实际开发中发现,这类系统最难处理的往往不是技术实现,而是如何平衡业务复杂度和技术架构的简洁性。
这个开源项目完整实现了车辆档案管理、使用登记、维修保养、状态监控等核心功能模块。采用前后端分离架构,后端基于SpringBoot 2.7提供RESTful API,前端使用Vue 3组合式API开发管理界面,数据库选用MySQL 8.0。整套代码包含详细的接口文档和初始化SQL脚本,开箱即用。
SpringBoot框架的选择主要基于其快速开发特性:
核心依赖包括:
xml复制<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
</dependency>
提示:在实际部署时需要注意SpringBoot与MyBatis的版本兼容性问题,特别是使用PageHelper分页插件时
Vue 3的组合式API相比选项式API更适合复杂业务场景:
项目前端工程结构:
code复制src/
├── api/ # 接口定义
├── assets/ # 静态资源
├── components/ # 公共组件
├── router/ # 路由配置
├── store/ # Pinia状态管理
├── utils/ # 工具函数
└── views/ # 页面组件
sql复制CREATE TABLE `vehicle_info` (
`id` int NOT NULL AUTO_INCREMENT,
`plate_number` varchar(20) NOT NULL COMMENT '车牌号',
`vehicle_type` varchar(50) NOT NULL COMMENT '车辆类型',
`purchase_date` date NOT NULL COMMENT '购置日期',
`status` tinyint NOT NULL DEFAULT '0' COMMENT '使用状态',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_plate` (`plate_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
车辆管理系统主要涉及以下几类数据关联:
注意:在设计关联查询时要特别注意N+1问题,建议使用MyBatis的关联映射或手动编写JOIN查询
状态机设计采用枚举类实现:
java复制public enum VehicleStatus {
IDLE(0, "闲置"),
IN_USE(1, "使用中"),
MAINTENANCE(2, "维修中"),
SCRAPPED(3, "已报废");
private final int code;
private final String desc;
// 构造方法、getter省略
}
状态变更的幂等性处理:
java复制@Transactional
public boolean changeStatus(Long vehicleId, VehicleStatus newStatus) {
Vehicle vehicle = vehicleMapper.selectById(vehicleId);
if (vehicle.getStatus() == newStatus.getCode()) {
return true; // 状态相同直接返回
}
// 状态校验逻辑...
vehicle.setStatus(newStatus.getCode());
return vehicleMapper.updateById(vehicle) > 0;
}
后端分页实现:
java复制@GetMapping("/usage-records")
public PageResult<UsageRecordVO> listUsageRecords(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String plateNumber) {
PageHelper.startPage(pageNum, pageSize);
List<UsageRecord> records = usageRecordMapper.selectByCondition(plateNumber);
PageInfo<UsageRecord> pageInfo = new PageInfo<>(records);
return new PageResult<>(
pageInfo.getTotal(),
records.stream().map(this::convertToVO).collect(Collectors.toList())
);
}
前端分页组件封装:
vue复制<template>
<el-pagination
:current-page="pagination.current"
:page-size="pagination.size"
:total="pagination.total"
@current-change="handlePageChange"
layout="total, sizes, prev, pager, next, jumper"
/>
</template>
采用JWT + Spring Security实现:
java复制@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/api/auth/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JwtAuthenticationFilter(authenticationManager()))
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
基于注解的权限校验:
java复制@PreAuthorize("hasRole('ADMIN') || hasAuthority('vehicle:manage')")
@PostMapping("/vehicles")
public Result addVehicle(@RequestBody VehicleDTO dto) {
// 业务逻辑
}
bash复制mvn clean package -DskipTests
properties复制# application-prod.properties
spring.datasource.url=jdbc:mysql://localhost:3306/vehicle_db?useSSL=false
spring.datasource.username=root
spring.datasource.password=yourpassword
bash复制npm run build
nginx复制server {
listen 80;
server_name yourdomain.com;
location / {
root /path/to/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://localhost:8080;
}
}
开发环境配置:
java复制@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*");
}
}
生产环境建议通过Nginx反向代理解决跨域。
常见症状:
检查要点:
我在实际开发中发现,车辆管理系统最容易被忽视的是状态变更的历史追溯。建议添加如下设计:
sql复制CREATE TABLE `status_change_log` (
`id` bigint NOT NULL AUTO_INCREMENT,
`vehicle_id` int NOT NULL,
`from_status` tinyint NOT NULL,
`to_status` tinyint NOT NULL,
`change_time` datetime NOT NULL,
`operator` varchar(50) NOT NULL,
`remark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_vehicle` (`vehicle_id`)
);
这个设计可以帮助后续审计和问题排查,特别是在车辆使用纠纷发生时。