没有模板引擎的 Micronaut 视图渲染 [英] Micronaut view rendering without template engine
本文介绍了没有模板引擎的 Micronaut 视图渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
micronaut 可以渲染静态文件吗?
Can micronaut render static files?
我在 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
不会呈现视图.
A requesting localhost:8080/main
does not render the view.
推荐答案
这符合设计.当无法将模型应用于视图时,应用视图模型逻辑没有意义.
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/**
通过上述配置,src/main/resources/views
中的 index.html
文件将在 /main
URL 为访问.
With the above configuration an index.html
file in src/main/resources/views
will be served when the /main
URL is accessed.
这篇关于没有模板引擎的 Micronaut 视图渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文