我最近发现 Yeoman ,极大方便的工具 JS 依赖和构建生命周期管理 .
此外,我使用 Maven 作为我的 Java 依赖和构建工具。我实际上是在寻求整合这两种工具,以便我能够两全其美。
看来社区在 上付出了很多努力Maven/Yeoman 整合各种文章,例如这篇:http://addyosmani.com/blog/making-maven-grunt/以及 yeoman-maven 插件 :https://github.com/trecloux/yeoman-maven-plugin
最后,我使用 Thymeleaf作为我的 Spring-MVC 模板解决方案。
假设以下目录布局(参见上面的 yeoman-maven-plugin):
pom.xml
- src
- main
- java
- webapp
- …
- test
- ..
- yo
package.json
component.json
Gruntfile.js
- app
index.html
...
- test
...
- dist
...
我的问题是 我的 Thymeleaf 模板应该放在哪里 ?
yo/app
目录? (它们随后会被 maven 复制到适当的目录中)src/main/webapp/WEB-INF/templates
目录? 在 的情况下我无法弄清楚什么AngularJS 例如,考虑到 Yeoman 假定模板/页面位于其
app
下,应用程序是何时以及如何与 servlet 容器交互的模板/页面,包括服务器端内容。目录...
最佳答案
如果您正在使用 Thymeleaf
作为您的 templating engine with Spring ,我假设你有类似的东西
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
</bean>
换句话说,您的模板应该位于
ServletContextTemplateResolver
中指定的文件夹中。属性(property)prefix
.在上面的例子中,就是 /WEB-INF/templates
.因此,这些应该在 /src/main/webapp/WEB-INF/templates
中.如果您没有使用
ServletContextTemplateResolver
,而是使用 ClassLoaderTemplateResolver
,您可以将它们放在应用程序类路径中的任何位置,并在该 bean 的属性中指定它。还有一个FileTemplateResolver
您可以在其中指定文件系统上任何位置的绝对路径。使用 Eclipse(maven 插件)构建应用程序时,具有文件夹
/src
/main
/webapp
/WEB-INF
/templates
/some-template.html
/index.html
/java
/com
/yourcompany
/Main.java
/resources
/some-properties.properties
maven 将生成以下内容
/WEB-INF
/templates
/some-template.html
/index.html
/classes
/com
/yourcompany
/Main.class
/some-properties.properties
作为扩展
.war
并将其提供给您的 servlet 容器,例如。 Tomcat 。
关于eclipse - 关于 Yeoman、Maven 和 Thymeleaf HTML 模板位置的询问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18806078/