Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Templates in a Spring MVC web application

I have a lot of common areas in my web application design, for example footer, header sidebar, blocks...etc and going through all of the application JSP files to change something for example in the header is pretty hectic so I was wondering if I can make something like template files for common areas for example header template, sidebar template, footer template, then I can include such templates in any JSP inside my application?

I am using Spring MVC framework to build my application

like image 766
MChan Avatar asked Oct 13 '13 15:10

MChan


People also ask

What are templates in spring?

Spring templates are a way to eliminate boilerplate code that is needed to correctly use many APIs such as JDBC, JMS, transactions, etc. Boilerplate code is setup and error handling code that needs to be written in order to use correctly a API.

What are templates in spring boot?

Spring Boot starters are templates that contain a collection of all the relevant transitive dependencies that are needed to start a particular functionality. Each starter has a special file, which contains the list of all the provided dependencies Spring provides. These files can be found inside pom.

What is the default HTML template in spring boot?

The default template directory is src/main/resources/templates . This is the Maven build file. The spring-boot-devtools enables hot swapping, disables template cache and enables live reloading. The spring-boot-starter-thymeleaf is a starter for building Spring MVC applications with Thymeleaf.

Does Spring MVC provides predefined templates for JDBC Hibernate and JPA?

Predefined Templates Spring framework provides templates for JDBC, Hibernate, JPA etc. technologies. So there is no need to write too much code. It hides the basic steps of these technologies.


2 Answers

As for templating you have the following options:

  1. Custom JSP tags. These tags may exist as Java classes or JSP snippets and provide a basic facility to encapsulate and reuse parts of JSP pages (headers, footers, etc.). See more in this manual

  2. Template engines like Tiles or decorators like Sitemesh. They are quite powerfull in building complex page layouts.

If you're looking for custom UI themes support please take a look at custom themes support in Spring MVC.

like image 74
Jk1 Avatar answered Oct 13 '22 00:10

Jk1


I have used Apache Tiles. It can be very easily integrated with Spring MVC. You can also consider using sitemesh. As you mentioned header template, footer template you can have base template for header, footer, menu and you can integrate them into base template,

Note : You can only have jsp and not html here.

Check this link for spring with tiles.

http://www.springbyexample.org/examples/dynamic-tiles-spring-mvc-module.html

like image 31
pappu_kutty Avatar answered Oct 13 '22 00:10

pappu_kutty