JAVA 将数据库中的内容转化为HTML
来源:互联网 发布:挖掘社交网络 中文版 编辑:程序博客网 时间:2024/05/15 14:46
/**
* 将数据库中的内容转化为HTML
*data 存在数据库内字段的内容
*formId是数据库内该条信息的ID
*filePath是生成的html文件所存放的位置
* @param image
* @return
*/
public void formToHtml(String data, String FormId, String filePath) {
StringBuffer buf = new StringBuffer("");
buf.append("<html>");
buf
.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />");
buf.append("<title>sdsds</title>");
buf.append("<head>");
buf.append("</head>");
buf.append("<body>");
buf.append(data);
buf.append("</body>");
buf.append("</html>");
String fileName = filePath + FormId + ".html";
ObjectOutputStream objOutputStream;
try {
objOutputStream = new ObjectOutputStream(new FileOutputStream(
new File(fileName)));
objOutputStream.writeObject(buf.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 将数据库中的内容转化为HTML
*vmBasePath vm模板所存放的位置 例如D:\\projectPath\\attach\\html
*vmTempName vm模板的名称
*dataContext 存在数据库内字段的内容
*HtmlFilePath 生成的html所存放的路径 例如:"D:\\projectPath\\attach\\html\\test.html"
* @param image
* @return
*/
public String dataToHtml(String vmBasePath, String vmTempName,
String dataContext, String HtmlFilePath) throws Exception {
// 初始化并取得Velocity引擎
VelocityEngine ve = new VelocityEngine();
// 设置路径
Properties properties = new Properties();
String basePath = vmBasePath;
// String basePath = "D:\\projectPath\\attach\\html";
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, basePath);
ve.init(properties);
// 取得velocity的模版
// Template t = ve.getTemplate("104.vm");
Template t = ve.getTemplate(vmTempName);
// 取得velocity的上下文context
VelocityContext context = new VelocityContext();
// 把数据填入上下文
// context.put("name", "Liang");
context.put("name", dataContext);
// 输出流
StringWriter writer = new StringWriter();
// 转换输出
t.merge(context, writer);
// PrintWriter filewriter = new PrintWriter(new
// FileOutputStream("D:\\projectPath\\attach\\html\\test.html"), true);
FileOutputStream fos = new FileOutputStream(HtmlFilePath);
PrintWriter filewriter = new PrintWriter(fos, true);
filewriter.println(writer.toString());
filewriter.flush();
filewriter.close();
fos.flush();
fos.close();
System.out.println("输出已经完成!");
return "success";
}
* 将数据库中的内容转化为HTML
*data 存在数据库内字段的内容
*formId是数据库内该条信息的ID
*filePath是生成的html文件所存放的位置
* @param image
* @return
*/
public void formToHtml(String data, String FormId, String filePath) {
StringBuffer buf = new StringBuffer("");
buf.append("<html>");
buf
.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />");
buf.append("<title>sdsds</title>");
buf.append("<head>");
buf.append("</head>");
buf.append("<body>");
buf.append(data);
buf.append("</body>");
buf.append("</html>");
String fileName = filePath + FormId + ".html";
ObjectOutputStream objOutputStream;
try {
objOutputStream = new ObjectOutputStream(new FileOutputStream(
new File(fileName)));
objOutputStream.writeObject(buf.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 将数据库中的内容转化为HTML
*vmBasePath vm模板所存放的位置 例如D:\\projectPath\\attach\\html
*vmTempName vm模板的名称
*dataContext 存在数据库内字段的内容
*HtmlFilePath 生成的html所存放的路径 例如:"D:\\projectPath\\attach\\html\\test.html"
* @param image
* @return
*/
public String dataToHtml(String vmBasePath, String vmTempName,
String dataContext, String HtmlFilePath) throws Exception {
// 初始化并取得Velocity引擎
VelocityEngine ve = new VelocityEngine();
// 设置路径
Properties properties = new Properties();
String basePath = vmBasePath;
// String basePath = "D:\\projectPath\\attach\\html";
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, basePath);
ve.init(properties);
// 取得velocity的模版
// Template t = ve.getTemplate("104.vm");
Template t = ve.getTemplate(vmTempName);
// 取得velocity的上下文context
VelocityContext context = new VelocityContext();
// 把数据填入上下文
// context.put("name", "Liang");
context.put("name", dataContext);
// 输出流
StringWriter writer = new StringWriter();
// 转换输出
t.merge(context, writer);
// PrintWriter filewriter = new PrintWriter(new
// FileOutputStream("D:\\projectPath\\attach\\html\\test.html"), true);
FileOutputStream fos = new FileOutputStream(HtmlFilePath);
PrintWriter filewriter = new PrintWriter(fos, true);
filewriter.println(writer.toString());
filewriter.flush();
filewriter.close();
fos.flush();
fos.close();
System.out.println("输出已经完成!");
return "success";
}
- JAVA 将数据库中的内容转化为HTML
- 将文件中的内容转化为数组
- 将.md转化为.html
- java 将数据库中的数据转化为easyUI treegrid json格式
- 将HTML转化为TEXT的Java类
- 使用java将 WORD,EXCEL转化为HTML
- java引用POI将Word转化为HTML
- dom4j将数据库中的数据转化为xml格式
- 将文件内容转化为二维数组
- JAVA 过滤标签将html内容转换为文本
- JAVA 过滤标签将html内容转换为文本
- 将json字符串转化为json数组,以及转化为java中的集合
- 将word文档转化为html(代码)
- 将excel表格转化为html文本
- 将html转化为JPG存档
- poi将word docx转化为html
- 纯JS实现将DIV中的内容转化为PNG图片
- 将HTML中的特殊字符转化为可显示的字符
- 内核模块相关命令
- JAVA 将图片转换成pdf文件
- 真的累了【转载】
- 十个应该知道的正则表达式例子
- mysql第二课命令dml
- JAVA 将数据库中的内容转化为HTML
- 一 信息系统
- MySQL 关于表复制 insert into 语法
- JAVA 删除文件以及文件夹
- 2.1软件工程上软件设计测试
- 对即将放弃以及快要放弃的人说……
- 刘德华的麦克风
- LiveStats:iPad上的网站实时统计工具
- 送给即将走出校门的同学们