---
title: "StringTemplate学习笔记(一) 简介"
author: "orange5458"
date: "2011-08-21T09:47:28Z"
tags: []
categories: ["开源软件"]
slug: "stringtemplate"
draft: false
lastmod: "2011-08-21T10:26:42Z"
id: 1154339
url: "https://orange5458.iteye.com/blog/1154339"
---

一，简介

      StringTemplate（简称ST）是一个基于Java的模板引擎库（目前同时支持C#、Python、Ruby），可以用于生成源代码、Web页面、电子邮件等各种有格式的文本。StringTemplate不同于其他类似的模板引擎的显著特点是严格执行模型视图分离，尤其擅长多目标代码生成、多种网站风格管理以及网站多语言版本生成等。StringTemplate已经应用到许多大型网站中，例如jGuru.com。

二，特点

      使用StringTemplate可以严格保证业务逻辑和表现逻辑相分离，不会互相干扰，提高网站的开发和维护的效率。模型和视图分离所带来的优点包括：模板文件可以在相似的网站开发中重用，清晰的模板文件可以做为网站开发的说明文档，模板文件可以单独修改。

三，安装

     将相关包stringtemplate.jar（3.2）， antlr-2.7.7.jar（依赖包） 通过eclipse添加到BUILD PATH里

四，hello world

```
package com.siyuan.st.test;

import org.antlr.stringtemplate.StringTemplate;

public class STTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringTemplate st = new StringTemplate("hello world");
		System.out.println(st.toString());
	}

}
```

五，运行结果

```
hello world
```

六，学习资料，LIB以及API

    官方文档：[http://www.antlr.org/wiki/display/ST/ST+condensed+--+Templates+and+expressions#STcondensed--Templatesandexpressions-Contents](http://www.antlr.org/wiki/display/ST/ST+condensed+--+Templates+and+expressions#STcondensed--Templatesandexpressions-Contents)

    其余见附件