Micronaut view rendering without template engine

∥☆過路亽.° 提交于 2019-12-11 05:25:48

问题


Can micronaut render static files?

I added compile 'io.micronaut:micronaut-views' into build.gradle

The Controller:

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

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

The index.html file is under /src/main/resources/views/index.html

A requesting localhost:8080/main does not render the view.


回答1:


This is behaving as designed. There is no point in applying view model logic when there is no way to apply the model to the view.

You can achieve the desired effect by simply configuring static resources. For example:

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

With the above configuration an index.html file in src/main/resources/views will be served when the /main URL is accessed.



来源:https://stackoverflow.com/questions/55972051/micronaut-view-rendering-without-template-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!