---
title: "Velocity 入门之 hello"
author: "charm_888"
date: "2008-07-17T11:36:06Z"
tags: []
slug: "velocity-hello"
draft: false
lastmod: "2008-07-17T11:36:06Z"
id: 215718
url: "https://charm.iteye.com/blog/215718"
---

```
这里是java文件
```

```
package com.makepolo.common.tools;

import java.io.BufferedWriter;

import java.io.OutputStreamWriter;

import org.apache.velocity.Template;

import org.apache.velocity.VelocityContext;

import org.apache.velocity.app.Velocity;

public class CreateType  {

	public static void main(String[] args) throws Exception {

		Velocity.init();

		VelocityContext context = new VelocityContext();

		context.put("name", "yy");

		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
				System.out));

		Template template = Velocity.getTemplate("web/html/category/hello.vm");

		template.merge(context, writer);

		writer.flush();

		writer.close();

	}

}
```

```
这里是模板文件：hello.vm
```

```
Hello, $name
```

```
注意：Template template = Velocity.getTemplate("web/html/category/hello.vm");
这句是模板 hello.vm 的存放位置；web 是工程目录； 
```