Find file History
Latest commit b93356d Nov 5, 2016 @tipsy tipsy Update velocity engine
Permalink
..
Failed to load latest commit information.
src Update velocity engine Nov 5, 2016
README.md Update README.md May 20, 2015
pom.xml Update velocity engine Nov 5, 2016

README.md

spark-template-velocity

How to use the Apache Velocity template route for Spark example:

import static spark.Spark.get;

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

import spark.Request;
import spark.Response;
import spark.template.velocity.VelocityEngine;

/**
 * VelocityTemplateRoute example.
 */
public final class VelocityExample {

    public static void main(final String[] args) {

        get("/hello", (request, response) -> {
            Map<String, Object> model = new HashMap<>();
            model.put("hello", "Velocity World");
            model.put("person", new Person("Foobar"));

            // The wm files are located under the resources directory
            return new ModelAndView(model, "hello.vm");
        }, new VelocityTemplateEngine());

    }

    public static class Person {
        private String name;

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

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