带火花的问候世界:
get(new Route("/hello") {
@Override
public Object handle(Request request, Response response) {
response.type("text/html");
return "<h1>Hello Spark MVC Framework!</h1>";
}
});
如何返回静态文件index.html?
注意:
答案 0 :(得分:7)
我知道我参加聚会很晚,你可以做到以下几点:
staticFiles.location("/public");
//在'public'
文件夹下创建一个名为'src/main/resources'
的文件夹
初始化应用时,请在routes
或requests
之前调用上述方法。这非常重要。
在"controller"
中,您可以这样添加:
的Response.Redirect(&#34;的test.html&#34); return null;
答案 1 :(得分:5)
您可以通过在此方法中将绝对路径传递到静态资源目录来执行此操作:
externalStaticFileLocation("/var/www/public");
或者通过传递此方法中的相对路径:
staticFileLocation("/public");
在设置任何路线之前调用此方法。在静态资源目录的根目录中创建index.html文件。