Spark Javaフレームワークには新しく、Freemarkerテンプレートエンジンを使用してhtmlファイルをレンダリングしようとしています。しかし、私はCSSとjsファイルをレンダリングできません。Spark Java Template Engineを使用してcssファイルとjsファイルをレンダリングできない
次のように私のプロジェクト構造は次のとおりです。
./pom.xml
./src/main/java/Spark.java
./src/main/resources/css/bootstrap.css
./src/main/resources/js/bootstrap.min.js
./src/main/resources/js/app.js
./src/main/resources/templates/search.ftl
次のように主な方法は次のとおりです。
public static void main(String[] args) {
BasicConfigurator.configure();
staticFileLocation("/css");
staticFileLocation("/Content/Images");
staticFileLocation("/fonts");
staticFileLocation("/js");
final Configuration configuration = new Configuration();
configuration.setClassForTemplateLoading(Spark.class, "/");
get("/searchview", (request, response) -> {
StringWriter writer = new StringWriter();
try {
Template searchTemplate = configuration.getTemplate("templates/search.ftl");
searchTemplate.process(null, writer);
} catch (Exception e) {
halt(500);
}
return writer;
});
}
そして今、私は次のURLを入力します。localhostを:4567/searchview、私のHTMLページがレンダリングされますしかし、CSSとJSはそうではありません。私のコンソールで
それは言う:INFO spark.http.matching.MatcherFilter - 要求されたルート[/css/bootstrap.min.css]は、Spark
にマッピングされていない、私は何をしないのですか?