spark-template-thymeleaf

Thymeleaf Template View Route implementation for Spark

License

License

Categories

Categories

Leaf Data Databases
GroupId

GroupId

com.github.mwmahlberg.sparkjava
ArtifactId

ArtifactId

spark-template-thymeleaf
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

spark-template-thymeleaf
Thymeleaf Template View Route implementation for Spark
Project URL

Project URL

https://github.com/mwmahlberg/spark-template-thymeleaf
Source Code Management

Source Code Management

https://github.com/mwmahlberg/spark-template-thymeleaf

Download spark-template-thymeleaf

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mwmahlberg.sparkjava/spark-template-thymeleaf/ -->
<dependency>
    <groupId>com.github.mwmahlberg.sparkjava</groupId>
    <artifactId>spark-template-thymeleaf</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mwmahlberg.sparkjava/spark-template-thymeleaf/
implementation 'com.github.mwmahlberg.sparkjava:spark-template-thymeleaf:0.0.1'
// https://jarcasting.com/artifacts/com.github.mwmahlberg.sparkjava/spark-template-thymeleaf/
implementation ("com.github.mwmahlberg.sparkjava:spark-template-thymeleaf:0.0.1")
'com.github.mwmahlberg.sparkjava:spark-template-thymeleaf:jar:0.0.1'
<dependency org="com.github.mwmahlberg.sparkjava" name="spark-template-thymeleaf" rev="0.0.1">
  <artifact name="spark-template-thymeleaf" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mwmahlberg.sparkjava', module='spark-template-thymeleaf', version='0.0.1')
)
libraryDependencies += "com.github.mwmahlberg.sparkjava" % "spark-template-thymeleaf" % "0.0.1"
[com.github.mwmahlberg.sparkjava/spark-template-thymeleaf "0.0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
com.sparkjava : spark-core jar 2.0.0
org.thymeleaf : thymeleaf jar 2.1.3.RELEASE
nz.net.ultraq.thymeleaf : thymeleaf-layout-dialect jar 1.2.5

Project Modules

There are no modules declared in this project.

spark-template-thymeleaf

Build Status

Note: By default, spark-template-thymeleaf expects all templates to be under META-INF/templates, to be valid HTML5 (otherwise an exception is thrown during rendering) and have .html as the file suffix. So the path for the template in this example would be /META-INF/templates/testpage.html

How to use the Thymeleaf template route for Spark example:

package spark.template.thymeleaf.example;

import static spark.Spark.get;

import java.util.HashMap;
import java.util.Map;

import spark.ModelAndView;
import spark.Request;
import spark.Response;
import spark.TemplateViewRoute;
import spark.template.thymeleaf.ThymeleafTemplateEngine;

public class ThymeleafExample {

	public static class Author {
		private String name;

		public Author(String name) {
			this.name = name;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
	}

	public static class TestViewRoute implements TemplateViewRoute {

		public ModelAndView handle(Request request, Response response) {
			Map<String, Object> model = new HashMap<String, Object>();
			model.put("title", "testpage");
			model.put("author", new Author(
					"Markus W Mahlberg <[email protected]"));

			return new ModelAndView(model, "testpage");
		}

	};

	public static void main(String[] args) {
		get("/hello", new TestViewRoute(), new ThymeleafTemplateEngine());
	}

}

Versions

Version
0.0.1