没有模板引擎的 Micronaut 视图渲染
Micronaut view rendering without template engine
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
未呈现视图。
这是按设计运行的。当无法将模型应用于视图时,应用视图模型逻辑毫无意义。
只需配置static resources即可达到预期效果。例如:
micronaut:
router:
static-resources:
main:
paths: classpath:views
mapping: /main/**
通过上述配置,src/main/resources/views
中的 index.html
文件将在访问 /main
URL 时提供。
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
未呈现视图。
这是按设计运行的。当无法将模型应用于视图时,应用视图模型逻辑毫无意义。
只需配置static resources即可达到预期效果。例如:
micronaut:
router:
static-resources:
main:
paths: classpath:views
mapping: /main/**
通过上述配置,src/main/resources/views
中的 index.html
文件将在访问 /main
URL 时提供。