【计算机毕设项目推荐】基于SpringBoot的springboot合庆镇停车场车位预约系统
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/parking")
public class ParkingController {
@Autowired
private ParkingService parkingService;
// 获取所有车位信息
@GetMapping("/list")
public List<ParkingSpace> getAllParkingSpaces() {
return parkingService.list();
}
// 分页获取车位信息
@GetMapping("/page")
public Page<ParkingSpace> getParkingSpacesByPage(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
return parkingService.page(new Page<>(page, size));
}
// 根据条件查询车位
@GetMapping("/search")
public List<ParkingSpace> searchParkingSpaces(ParkingSearchParams params) {
QueryWrapper<ParkingSpace> queryWrapper = new QueryWrapper<>();
if (params.getAvailable() != null) {
queryWrapper.eq("available", params.getAvailable());
}
if (params.getArea() != null) {
queryWrapper.eq("area", params.getArea());
}
return parkingService.list(queryWrapper);
}
// 预约车位
@PostMapping("/reserve")
public boolean reserveParkingSpace(@RequestBody ParkingReservation reservation) {
return parkingService.reserve(reservation);
}
// 取消预约
@DeleteMapping("/cancel/{id}")
public boolean cancelReservation(@PathVariable Long id) {
return parkingService.cancelReservation(id);
}
// 车位预约状态更新
@PutMapping("/update/{id}")
public boolean updateParkingSpaceStatus(@PathVariable Long id, @RequestBody ParkingSpace parkingSpace) {
return parkingService.updateById(parkingSpace);
}
// 定义用于搜索的参数类
public static class ParkingSearchParams {
private Boolean available;
private String area;
// getters and setters
public Boolean getAvailable() { return available; }
public void setAvailable(Boolean available) { this.available = available; }
public String getArea() { return area; }
public void setArea(String area) { this.area = area; }
}
// 定义预约请求的类
public static class ParkingReservation {
private Long spaceId;
private String userId;
// getters and setters
public Long getSpaceId() { return spaceId; }
public void setSpaceId(Long spaceId) { this.spaceId = spaceId; }
public String getUserId() { return userId; }
public void setUserId(String userId) { this.userId = userId; }
}
}