Last active
June 11, 2021 21:21
-
-
Save Badbird5907/b6a4ee93788bef4bb063a92698312fc2 to your computer and use it in GitHub Desktop.
A builder I made for apache's velocity template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Getter; | |
import lombok.Setter; | |
import spark.ModelAndView; | |
import spark.template.velocity.VelocityTemplateEngine; | |
import java.util.HashMap; | |
@Getter | |
@Setter | |
public class VelocityTemplateBuilder { | |
private HashMap<String,Object> model = new HashMap<>(); | |
private String viewName; | |
public VelocityTemplateBuilder(String viewName){ | |
this.viewName = viewName; | |
if (!this.viewName.endsWith(".vm")) | |
this.viewName = viewName + ".vm"; | |
} | |
public VelocityTemplateBuilder addEntry(String key,Object value){ | |
model.put(key,value); | |
return this; | |
} | |
public String build(){ | |
return new VelocityTemplateEngine().render(new ModelAndView(model,viewName)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment