驾驶员及车辆信息控制类

master
xxy 2 months ago
parent 0d0f660aaa
commit 12ea837508

@ -0,0 +1,54 @@
package com.example.api.controller;
import com.example.api.annotation.Log; // 导入自定义的日志注解,用于记录操作日志
import com.example.api.model.entity.Driver; // 导入Driver实体类代表驾驶员信息
import com.example.api.model.enums.BusinessType; // 导入BusinessType枚举定义不同的业务操作类型
import com.example.api.service.DriverService; // 导入DriverService服务类包含对Driver数据的操作
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; // 导入Resource注解用于依赖注入
import java.util.List; // 导入List接口用于处理列表数据
// 定义RestController注解标识该类为一个RESTful控制器
@RestController
// 定义RequestMapping注解设置基础URL路径为"/api/driver"所有方法的URL都将在此基础上构建
@RequestMapping("/api/driver")
public class DriverController {
// 使用@Resource注解自动注入DriverService服务用于处理驾驶员相关的业务逻辑
@Resource
private DriverService driverService;
// 使用@Log注解记录插入操作的日志模块为"驾驶员管理"操作类型为BusinessType.INSERT
@Log(module = "驾驶员管理", type = BusinessType.INSERT)
// 处理POST请求用于保存驾驶员信息
@PostMapping("")
public Driver save(@RequestBody Driver driver) {
return driverService.save(driver);
}
// 使用@Log注解记录查询操作的日志模块为"驾驶员管理"操作类型为BusinessType.QUERY
@Log(module = "驾驶员管理", type = BusinessType.QUERY)
// 处理GET请求用于查询所有驾驶员信息
@GetMapping("")
public List<Driver> findAll() {
return driverService.findAll();
}
// 使用@Log注解记录查询操作的日志模块为"驾驶员管理"操作类型为BusinessType.QUERY
@Log(module = "驾驶员管理", type = BusinessType.QUERY)
// 处理GET请求通过URL中的{id}路径变量查询特定驾驶员信息
@GetMapping("/{id}")
public Driver findById(@PathVariable String id) {
return driverService.findById(id);
}
// 使用@Log注解记录删除操作的日志模块为"驾驶员管理"操作类型为BusinessType.DELETE
@Log(module = "驾驶员管理", type = BusinessType.DELETE)
// 处理DELETE请求通过URL参数{id}删除特定驾驶员信息
@DeleteMapping("")
public void delete(String id) {
driverService.delete(id);
}
}

@ -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);
}
}
Loading…
Cancel
Save