【问题标题】:Micronaut SPA ContollerMicronaut SPA 控制器
【发布时间】:2020-06-12 15:28:24
【问题描述】:

这是非常标准的 Spring SPA 控制器。

@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。

【问题讨论】:

  • 什么情况下不知道索引文件在哪里?

标签: java micronaut


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-11-27
    • 1970-01-01
    • 2019-04-22
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    相关资源
    最近更新 更多