春季启动:2.3.3.RELEASE
爪哇:11
我使用webflux + RouterFunction + Thymeleaf并遇到错误“无法解析名称为'index'的视图”。
index.html在“资源/模板”下。我把一些看起来很重要的源代码。
如果使用“ RouterFunction”,是否不能使用Thymeleaf?
如果您需要更多详细信息,请随时发表评论。
######## handler ###########
@Component
public class ItemHandler {
public RouterFunction<ServerResponse> routes = route()
.path("/item", builder -> builder.GET("/", this::index))
.build();
public Mono<ServerResponse> index(ServerRequest request) {
Map<String, Object> attributes = new HashMap<>();
attributes.put("items", "Hello");
return ServerResponse.ok().contentType(MediaType.TEXT_HTML)
.render("index", attributes);
}
}
######## index.html ###########
<!DOCTYPE html>
<html lang="ja"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
<h1>FluxTest</h1>
</body>
</html>
######## entry point ###########
@SpringBootApplication
public class DemoWebfluxApplication {
public static void main(String[] args) {
SpringApplication.run(DemoWebfluxApplication.class, args);
}
}
负责处理静态文件位置的默认属性为spring.resources.static-locations
。
默认值为/META-INF/resources/, /resources/, /static/, /public/
。您可以覆盖默认值,也可以将其放在index.html
这些位置之一。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句