Reputation: 2728
Currently I'm evaluating thymeleaf for one of our project below is the structure
as you can see fragments folder and the views are on the same level
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home";
}
my problem I'm not able to map fragments to fragments folder
keep in mind that I dont want to use return "views\home" as a solution ,also I don't want to move fragment folder inside the views folder
I need it simple just as the resolvers detect fragments it should route to fragment folder...
I believe some is missing in my work
Thanx
Upvotes: 0
Views: 2960
Reputation: 20135
Have you tried this:
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="characterEncoding" value="UTF-8" />
<property name="templateEngine">
<bean class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="dialects">
<set>
<bean class="org.thymeleaf.spring4.dialect.SpringStandardDialect" />
</set>
</property>
<property name="templateResolvers">
<set>
<bean class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="cacheable" value="false" />
<property name="prefix" value="/fragments/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="cacheable" value="false" />
<property name="prefix" value="/views/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
</set>
</property>
</bean>
</property>
</bean>
Note the two template resolvers, each mapped to its own path in the folder hierarchy.
Upvotes: 4
Reputation: 64039
What you are trying to do is not possible, since in order to integrate Spring MVC with Thymeleaf you had to specify WEB-INF/home
as the root path of the views.
I know you said you don't want to move fragments
inside views
, but that is the most logical solution and will work perfectly.
Check out this example project where the fragments are inside the views
Upvotes: 0