我有一个问题,我有两个实体,Driver
和Vehicle
一对多,
我正在尝试添加新的车辆,但是当我想找司机时得到了null pointer exception
。
@PostMapping("/vehicles/{driverId}/{plateNumber}/{vehicleType}")
public Vehicle addDriver(@PathVariable int driverId, @PathVariable String plateNumber , @PathVariable String vehicleType) {
// also just in case they pass an id in JSON ... set id to 0
// this is to force a save of new item ... instead of update
**Driver theDriver = driverService.findById(driverId);**
System.out.println(theDriver.getFirstName());
Vehicle theVehicle = new Vehicle();
theVehicle.setId(0);
theVehicle.setPlateNumber(plateNumber);
theVehicle.setVehicleType(vehicleType);
theVehicle.setDriver(theDriver);
vehicleService.save(theVehicle);
return theVehicle;
}
此方法在Driver Rest Controller中运行良好。
有人可以帮助我解决我的问题吗?