关于Spring Flux / Mono响应的HATEOAS

问题描述 投票:7回答:1

我一直按照指南使用Spring 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);
    }
}

现在我想使用存储库并输出Flux / Mono响应:

@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?有可能吗?

spring spring-mvc spring-hateoas spring-webflux
1个回答
3
投票

我认为这个项目不支持(但是?)Spring Framework中的新反应支持。你最好的选择是reach out to the maintainers and contribute to the project(创建一个问题并解释你想要实现的目标是一个开始!)。

© www.soinside.com 2019 - 2024. All rights reserved.