之前学习过一种模板渲染技术是Thymleaf,今天讲解下另一种模板渲染技术Velocity!
知识点预习:
- 使用Properties封装Velocity的各种属性
- VelocityEngine根据Properties封装属性实例化模板引擎对象
- 实例化VelocityContext并在其中封装渲染数据
- VelocityEngine将上下文中的数据渲染至指定的模板中并将渲染后的页面数据写入StringWriter
- 通过HttpServletResponse的输出流将StringWriter中页面数据响应至前端
下面通过案例来展示!
一.案例展示
1.测试准备
项目工程(maven中选择webapp工程)
2.代码展示
***index.jsp
<%-- Created by IntelliJ IDEA. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<%
out.print("Hello,EveryBody!");
%>
</body>
</html>
<