只是一个基于maven结构的简单速度独立应用程序.这是用Scala编写的代码片段,用于helloworld.vm在${basedir}/src/main/resources文件夹中呈现模板:
com.ggd543.velocitydemo
import org.apache.velocity.app.VelocityEngine
import org.apache.velocity.VelocityContext
import java.io.StringWriter
/**
* @author ${user.name}
*/
object App {
def main(args: Array[String]) {
//First , get and initialize an engine
val ve = new VelocityEngine();
ve.init();
//Second, get the template
val resUrl = getClass.getResource("/helloworld.vm")
val t = ve.getTemplate("helloworld.vm"); // not work
// val t = ve.getTemplate("/helloworld.vm"); // not work
// val t = ve.getTemplate(resUrl.toString); // not work yet
//Third, create a context and add data
val context = new …Run Code Online (Sandbox Code Playgroud)