【问题标题】:Micronaut view rendering without template engine没有模板引擎的 Micronaut 视图渲染
【发布时间】:2019-05-03 14:38:29
【问题描述】:

micronaut 可以渲染静态文件吗?

我将compile 'io.micronaut:micronaut-views' 添加到build.gradle

控制器:

@Controller("/main")
public class MainController {

    @View("index.html")
    @Get("/")
    public HttpResponse index() {
        return HttpResponse.ok();
    }
}

index.html 文件位于/src/main/resources/views/index.html

发出请求的localhost:8080/main 不会呈现视图。

【问题讨论】:

    标签: micronaut viewrendering


    【解决方案1】:

    这是按设计运行的。当无法将模型应用到视图时,应用视图模型逻辑是没有意义的。

    只需配置static resources即可达到想要的效果。例如:

    micronaut:
      router:
        static-resources:
          main:
            paths: classpath:views
            mapping: /main/**           
    

    通过上述配置,当访问/main URL 时,将提供src/main/resources/views 中的index.html 文件。

    【讨论】:

    • 太棒了,那肯定行。谢谢!
    猜你喜欢
    • 2013-01-10
    • 1970-01-01
    • 2013-07-09
    • 2017-09-08
    • 2018-08-02
    • 2022-01-10
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    相关资源
    最近更新 更多