2

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不会呈现视图。

4

1 回答 1

7

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

只需配置静态资源就可以达到想要的效果。例如:

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

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

于 2019-05-03T18:51:46.377 回答