gpt4 book ai didi

java - Micronaut SPA Controller

转载 作者:行者123 更新时间:2023-12-01 16:18:13 25 4
gpt4 key购买 nike

这是非常标准的 Spring SPA Controller 。

@Controller
public class SPAController {

@GetMapping("/")
public String home() {
return "forward:/static/index.html";
}

@GetMapping("/**/{[path:[^\\.]*}")
public String html5Mode() {
return "forward:/static/index.html";
}
}

如何在 Micronaut 中做同样的事情?已经有一些关于 SO 的答案,比如这个:

@Get("/{[path:[^\\.]*}")
@Secured(SecurityRule.IS_ANONYMOUS)
@Produces(MediaType.TEXT_HTML)
public HttpResponse<?> refresh(HttpRequest<?> request) {
StreamedFile indexFile = new StreamedFile(res.getResource("classpath:public/index.html").get());
return HttpResponse.ok(indexFile);
}

这是完全错误的。我“不知道”index.html 文件位置,我只知道它的 URL。

最佳答案

我不知道在什么情况下您不知道索引文件在哪里,但是您可以使用 Micronaut http 客户端向为其提供服务的任何 URL 发出请求并返回该响应正文。

关于java - Micronaut SPA Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62347465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com