Java 可以从GetMapping(";/";)处理程序返回Mono.just(";index";)吗? 让我们考虑这个请求处理程序: @GetMapping("/") public Mono<String> index(Model model) { model.addAttribute("list", Flux.just("item1", "item2")); return Mono.just("list"); // <- Template name }

Java 可以从GetMapping(";/";)处理程序返回Mono.just(";index";)吗? 让我们考虑这个请求处理程序: @GetMapping("/") public Mono<String> index(Model model) { model.addAttribute("list", Flux.just("item1", "item2")); return Mono.just("list"); // <- Template name },java,spring-webflux,project-reactor,Java,Spring Webflux,Project Reactor,此处理程序仍未使用 似乎我必须从templates目录中删除index.html模板,才能处理GetMapping(“/”)路由 所以我的问题是,是否可以从GetMapping(“/”处理程序返回Mono.just(“index”)?因此,您应该使用@Controller而不是@RestController 这是另一个例子: @GetMapping("/welcome") public Mono<String> hello(final Model mode

此处理程序仍未使用

似乎我必须从
templates
目录中删除
index.html
模板,才能处理
GetMapping(“/”)
路由

所以我的问题是,是否可以从
GetMapping(“/”
处理程序返回
Mono.just(“index”)

因此,您应该使用@Controller而不是@RestController

这是另一个例子:

@GetMapping("/welcome")
    public Mono<String> hello(final Model model) {
        model.addAttribute("name", "Foo");
        model.addAttribute("city", "Bar");

        String path = "hello";
        return Mono.create(monoSink -> monoSink.success(path));
    }

@GetMapping(“/welcome”)
公共Mono hello(最终型号){
model.addAttribute(“名称”、“Foo”);
添加属性(“城市”、“酒吧”);
String path=“hello”;
返回Mono.create(monoSink->monoSink.success(path));
}
相应的thymeleaf html页面:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8"/>
    <title>Greet</title>
</head>

<body>

<p th:text="${name}"></p> lives in <p th:text="${city}"></p> 

</body>
</html> 

打招呼

居住在

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8"/>
    <title>Greet</title>
</head>

<body>

<p th:text="${name}"></p> lives in <p th:text="${city}"></p> 

</body>
</html>