|
|
|
@ -0,0 +1,65 @@
|
|
|
|
|
package com.example.api.controller;
|
|
|
|
|
|
|
|
|
|
// 导入自定义的日志注解类
|
|
|
|
|
import com.example.api.annotation.Log;
|
|
|
|
|
// 导入车辆实体类
|
|
|
|
|
import com.example.api.model.entity.Vehicle;
|
|
|
|
|
// 导入业务类型枚举类
|
|
|
|
|
import com.example.api.model.enums.BusinessType;
|
|
|
|
|
// 导入车辆服务接口
|
|
|
|
|
import com.example.api.service.VehicleService;
|
|
|
|
|
// 导入Spring框架的注解支持
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
// 使用javax.annotation.Resource注解来实现依赖注入
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
// 导入Java的util包,用于操作集合
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
// 使用RestController注解声明这是一个REST控制器
|
|
|
|
|
@RestController
|
|
|
|
|
// 使用RequestMapping注解指定这个控制器的基础URL路径为"/api/vehicle"
|
|
|
|
|
@RequestMapping("/api/vehicle")
|
|
|
|
|
public class VehicleController {
|
|
|
|
|
|
|
|
|
|
// 使用@Resource注解注入VehicleService
|
|
|
|
|
@Resource
|
|
|
|
|
private VehicleService vehicleService;
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"车辆管理",业务类型为BusinessType.INSERT(插入)
|
|
|
|
|
@Log(module = "车辆管理", type = BusinessType.INSERT)
|
|
|
|
|
// 使用PostMapping注解定义一个POST请求的处理器,用于保存车辆信息
|
|
|
|
|
@PostMapping("")
|
|
|
|
|
public Vehicle save(@RequestBody Vehicle vehicle) {
|
|
|
|
|
// 调用vehicleService的save方法保存车辆信息
|
|
|
|
|
return vehicleService.save(vehicle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"车辆管理",业务类型为BusinessType.QUERY(查询)
|
|
|
|
|
@Log(module = "车辆管理", type = BusinessType.QUERY)
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,用于获取所有车辆信息
|
|
|
|
|
@GetMapping("")
|
|
|
|
|
public List<Vehicle> findAll() {
|
|
|
|
|
// 调用vehicleService的findAll方法获取所有车辆信息
|
|
|
|
|
return vehicleService.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"车辆管理",业务类型为BusinessType.QUERY(查询)
|
|
|
|
|
@Log(module = "车辆管理", type = BusinessType.QUERY)
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,用于根据ID查询单个车辆信息
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
|
public Vehicle findById(@PathVariable String id) {
|
|
|
|
|
// 调用vehicleService的findById方法根据ID查询单个车辆信息
|
|
|
|
|
return vehicleService.findById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"车辆管理",业务类型为BusinessType.DELETE(删除)
|
|
|
|
|
@Log(module = "车辆管理", type = BusinessType.DELETE)
|
|
|
|
|
// 使用DeleteMapping注解定义一个DELETE请求的处理器,用于删除车辆信息
|
|
|
|
|
@DeleteMapping("")
|
|
|
|
|
public void delete(String id) {
|
|
|
|
|
// 调用vehicleService的delete方法删除车辆信息
|
|
|
|
|
vehicleService.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|