For inject @PathVariable
entity I mean
@RequestMapping(method = RequestMethod.PUT, path = "{project-id}")
@Transactional
@PreAuthorize("#user.id == #project.userId")
public Object update(@P("user") @Current User user,
@P("project") @PathVariable Project entity,
@RequestBody @Valid ProjectPost request) {
setProjectPostToEntity(entity, request);
return ResponseEntity.ok(ImmutableMap.of("message", "Project update successful"));
}
But the @PathVariable Project entity
will be null if project-id
not found in repository, what I want is something like this
@RequestMapping(method = RequestMethod.PUT, path = "{project-id}")
@Transactional
@PreAuthorize("#user.id == #project.userId")
public Object update(@P("user") @Current User user,
@P("project") @PathVariable @Valid @NotNull(message="Update project not exists") Project entity,
@RequestBody @Valid ProjectPost request) {
setProjectPostToEntity(entity, request);
return ResponseEntity.ok(ImmutableMap.of("message", "Project update successful"));
}
If project-id
not found in repository will return a message Update project not exists
, but @Valid @NotNull(message="Update project not exists")
not works here, how can I do something like this ?