Leveraging templates to create content
We can now switch to writing a Mustache template!
After creating the controller class earlier in this chapter, we don’t have to do much more. Spring Boot’s component scanning feature, as mentioned in Chapter 1, Core Features of Spring Boot, will do all the legwork of instantiating our controller class. Spring Boot’s autoconfiguration will add the extra beans that power Mustache’s templating engine, hooking it into Spring’s infrastructure.
We just need to craft the content that goes inside the template.
By default, Spring Boot expects all templates to be located at src/main/resources/templates
.
Tip
Spring Boot has configuration properties for template engines that default to putting all templates inside src/main/resources/templates
. Also, each templating engine has a suffix. For Mustache, it’s .mustache
. When we return index
from a controller method, Spring Boot transforms it into src/main...