Skip to content

This is a SpringBoot demo app that shows how to use Thymeleaf as a separate component, out from MVC cycle. Allows you to use Thymeleaf template system for other purposes like reporting, mailing, etc. It provides a service (TlTransformService) to apply a Thymeleaf template stored in database. Update: with Thymeleaf 3 this is no longer necessary, …

Notifications You must be signed in to change notification settings

spekdrum/thymeleaf-as-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Intro

This is a SpringBoot demo app that shows how to use Thymeleaf as a separate component, out from MVC cycle. Allows you to use Thymeleaf template system for other purposes like reporting, mailing, etc. It provides a service (TlTransformService) to apply a Thymeleaf template stored in database.

 

This is based on demo from Tomasz Kaczmarzyk at http://blog.kaczmarzyk.net/2015/01/04/loading-view-templates-from-database-with-thymeleaf

 

Use

mvn clean package

Run app executing Main method from org.spekdrum.thymeleafdb.ThymeleafDbSpringBootApplication

 

Go to this URL for test:

http://localhost:8080/?name=Sledge

 

How to use it in your Spring App

Take these classes:

  • SpringTemplateEngineConfig

  • TlDatabaseTemplateResolver

  • TlTransformService (not really necessary, but hides lots of public methods from SpringTemplateEngine).

  TlDatabaseTemplateResolver needs to be modified to use your own repository and template entity.

 

Applying a template

Context ctx = new Context();
ctx.setVariable("name", name);
String document = tlTransformService.applyTemplate("test-template", ctx);

About

This is a SpringBoot demo app that shows how to use Thymeleaf as a separate component, out from MVC cycle. Allows you to use Thymeleaf template system for other purposes like reporting, mailing, etc. It provides a service (TlTransformService) to apply a Thymeleaf template stored in database. Update: with Thymeleaf 3 this is no longer necessary, …

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages