ich die folgende Herausforderung möchte ich einen zusätzlichen Link zu einer Einheit fügen wie:Wie fügen Sie einen neuen _link zu einer Entität hinzu, indem Sie den Federdatenrest verwenden?
"_links": {
"self": {
"href": "http://localhost:8080/api/organizaciones"
},
"profile": {
"href": "http://localhost:8080/api/profile/organizaciones"
},
"search": {
"href": "http://localhost:8080/api/organizaciones/search"
},
"disable": {
"href": "http://localhost:8080/api/organizaciones/disable"
}
}
Die Idee hinter diesem Szenario ist, dass ich eine weiche löschen über einen eigenen Link innerhalb Organizacion Einheit aussetzen müssen ... jetzt bin ich nur in der Lage zu tun:
http://localhost:8080/api/organizaciones/search/disable?id=100
um die weiche löschen auszuführen ... hat jemand weiß, wie kann ich erreichen, das der richtige Weg? Oder ist es meine einzige Alternative, einen Controller zu erstellen?
Dank In Advanced.
HINWEIS:
ich es endlich herausgefunden, dass ich etwas erwähnt wurde von Alex (danke) auf den Kommentar unten.
BTW habe ich Kredit an den Vater des Frühlings-data-Rest geben @olivergieke ich eines seiner Beispiele geprüft, genauer: restbucks
1.) Zunächst erstellt die folgende Komponente
@Component
@RequiredArgsConstructor
public class OrganizacionResourceProcessor implements ResourceProcessor<Resource<Organizacion>>{
private static final String DISABLE_REL = "deshabilitar";
private static final String ENABLE_REL = "habilitar";
private final @NonNull EntityLinks entityLinks;
@Override
public Resource<Organizacion> process(Resource<Organizacion> resource) {
Organizacion organizacion = resource.getContent();
if(organizacion.isEnabled()){
resource.add(entityLinks.linkForSingleResource(Organizacion.class, organizacion.getId()).slash(DISABLE_REL).withRel(DISABLE_REL));
}
if(organizacion.isDisabled()){
resource.add(entityLinks.linkForSingleResource(Organizacion.class, organizacion.getId()).slash(ENABLE_REL).withRel(ENABLE_REL));
}
return resource;
}
}
erstellt dann den Controller diese beiden Operationen ... es
@RepositoryRestController
@RequestMapping("/organizaciones")
@ExposesResourceFor(Organizacion.class)
@RequiredArgsConstructor
@Slf4j
@Transactional
public class OrganizacionController {
private final @NonNull OrganizacionRepository organizacionRepository;
private final @NonNull EntityLinks entityLinks;
@GetMapping(value="/{id}/habilitar")
public ResponseEntity<?> desactivarOrganizacion(@PathVariable("id") Long id) {
Preconditions.checkNotNull(id);
Organizacion organizacion = organizacionRepository.findOne(id);
if(organizacion == null){
return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
}
organizacion.setEstado(Estado.DESHABILITADO);
Organizacion pOrg = this.organizacionRepository.save(organizacion);
HttpHeaders header = new HttpHeaders();
header.setLocation(this.entityLinks.linkForSingleResource(Organizacion.class, pOrg.getId()).toUri());//construimos el URL
return new ResponseEntity<Void>(header,HttpStatus.CREATED);
}
@GetMapping(value="/{id}/deshabilitar")
public ResponseEntity<?> activarOrganizacion(@PathVariable("id") Long id){
Preconditions.checkNotNull(id);
Organizacion organizacion = organizacionRepository.findOne(id);
if(organizacion == null){
return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
}
organizacion.setEstado(Estado.ACTIVO);
Organizacion pOrg = this.organizacionRepository.save(organizacion);
HttpHeaders header = new HttpHeaders();
header.setLocation(this.entityLinks.linkForSingleResource(Organizacion.class, pOrg.getId()).toUri());//construimos el URL
return new ResponseEntity<Void>(header,HttpStatus.CREATED);
}
}
und das war zu unterstützen.
Danke Leute.
Was genau ist das Problem? – zeroflagL