を使用してSpringMVCでResponseEntityを解決できません:は、これは私のコントローラであるJpaRepository
package com.hodor.booking.controller;
import com.hodor.booking.jpa.domain.Vehicle;
import com.hodor.booking.service.VehicleService;
import com.wordnik.swagger.annotations.Api;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/api/v1/vehicles")
@Api(value = "vehicles", description = "Vehicle resource endpoint")
public class VehicleController {
private static final Logger log = LoggerFactory.getLogger(VehicleController.class);
@Autowired
private VehicleService vehicleService;
@RequestMapping(method = RequestMethod.GET)
public List<Vehicle> index() {
log.debug("Getting all vehicles");
return vehicleService.findAll();
}
@RequestMapping(value="/save", method=RequestMethod.POST, consumes="application/json")
@ResponseBody
public Vehicle setVehicle(@RequestBody Vehicle vehicle) {
log.debug("Inserting vehicle");
if (vehicle.getLicensePlate() == null){
return new ResponseEntity<Void>(HttpStatus.CONFLICT);
}
return vehicleService.saveVehicle(vehicle);
}
}
私は何で達成したい上記のガードがいる場合、ケースに車両オブジェクトは、LicensePlateメンバーを持って戻って送信しない、ということですHTTPステータスヘッダーのCONFLICTまたは何かに従って。
私はノードとエクスプレスのバックグラウンドから来ており、私は自分のヘッダを設定し、応答を送り、それを使って完了しています。しかし、この場合(JPA)は動作していないようです。何か案は?
私は今このクラス "javax.validation.constraints.NotNull"から '@ NotNull'アノテーションを使用しています。 nullがtrueの場合、500 Server Errorを返します。Fair Enoughボーナスの場合、このような注釈もありますか? https://docs.oracle.com/javaee/7/api/javax/validation/constraints/Future.html。私はそれを見つけたと思う: '@ Future'注釈 - http://stackoverflow.com/questions/11624532/where-is-implementation-of-future-defined – nottinhill