2017-08-12 93 views
2

我一直在使用Spring HATEOAS以下準則:HATEOAS

https://spring.io/guides/gs/rest-hateoas/#initial

package hello; 

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*; 

import org.springframework.http.HttpEntity; 
import org.springframework.http.HttpStatus; 
import org.springframework.http.ResponseEntity; 
import org.springframework.web.bind.annotation.RestController; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 

@RestController 
public class GreetingController { 

    private static final String TEMPLATE = "Hello, %s!"; 

    @RequestMapping("/greeting") 
    public HttpEntity<Greeting> greeting(@RequestParam(value = "name", required = false, defaultValue = "World") String name) { 

     Greeting greeting = new Greeting(String.format(TEMPLATE, name)); 
     greeting.add(linkTo(methodOn(GreetingController.class).greeting(name)).withSelfRel()); 

     return new ResponseEntity<Greeting>(greeting, HttpStatus.OK); 
    } 
} 

現在我想用一個資源庫和輸出通量/黑白響應:

@RestController 
class PersonController { 

    private final PersonRepository people; 

    public PersonController(PersonRepository people) { 
     this.people = people; 
    } 

    @GetMapping("/people") 
    Flux<String> namesByLastname(@RequestParam Mono<String> lastname) { 

     Flux<Person> result = repository.findByLastname(lastname); 
     return result.map(it -> it.getFullName()); 
    } 
} 

如何在Flux/Mono響應中使用Spring HATEOAS?它有可能嗎?

回答