想了解【软件周刊第41期】模板引擎VelocityEngine发布2.0版本;Bootstrap4首个Beta版发布的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于EndAdminbe
想了解【软件周刊第 41 期】模板引擎 Velocity Engine 发布 2.0 版本;Bootstrap 4 首个 Beta 版发布的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于End Admin beta 测试版发布,基于 bootstrap 3.2 的后台模版、MyExcel 3.3.2 版本发布,velocity&enjoy 模板引擎支持、SpringBoot 使用 velocity 模板引擎、Springboot使用velocity模板引擎的新知识。
本文目录一览:- 【软件周刊第 41 期】模板引擎 Velocity Engine 发布 2.0 版本;Bootstrap 4 首个 Beta 版发布
- End Admin beta 测试版发布,基于 bootstrap 3.2 的后台模版
- MyExcel 3.3.2 版本发布,velocity&enjoy 模板引擎支持
- SpringBoot 使用 velocity 模板引擎
- Springboot使用velocity模板引擎
【软件周刊第 41 期】模板引擎 Velocity Engine 发布 2.0 版本;Bootstrap 4 首个 Beta 版发布
总结
以上是小编为你收集整理的【软件周刊第 41 期】模板引擎 Velocity Engine 发布 2.0 版本;Bootstrap 4 首个 Beta 版发布全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
End Admin beta 测试版发布,基于 bootstrap 3.2 的后台模版
更多功能陆续添加。。。
力求做一个 通用、简约、实用、多功能并存的后台模版,支持移动设备,放弃老版浏览器,仅支持高大上浏览器(chrome、firefox)。IE暂不考虑。 更重要的一点它是开源免费的。
Git@OSC:http://git.oschina.net/enond/End-Admin
项目下载:https://github.com/EnoND/EndAdmin/tree/master
项目演示:http://enond.github.io/EndAdmin/index.html
End Admin的宗旨就是提供一个后台的框架模版,尽量不去修改bootstrap的原生样式。如需其他样式请自行覆盖即可
仿Ace Admin制作,绝非复制粘贴,只取其布局和样式配置的创意。大量采用最新的bootstrap 3.2 原生的样式,这样后期制作完全可参考BS 官方文档 。
只提供特殊的组件或插件的演示及教程。
采用 seajs 2.3 动态加载模块,大大提升了加载速度。(玉柏说再多的插件也不用担心加载缓慢拉!o(∩_∩)o 哈哈)
MyExcel 3.3.2 版本发布,velocity&enjoy 模板引擎支持
MyExcel,是一个集导入、导出、加密Excel等多项功能的Java工具包。
MyExcel采用声明式语法来构建、读取Excel,屏蔽POI的具体操作细节(对POI无感知),以开发常用的技术替代,使得构建(从简单到高度复杂Excel)以及读取Excel变得极为便利。
如导入:
List<ArtCrowd> result = SaxExcelReader.of(ArtCrowd.class)
.sheet(0) // 0代表第一个,如果为0,可省略该操作,也可sheet("名称")读取
.rowFilter(row -> row.getRowNum() > 0) // 如无需过滤,可省略该操作,0代表第一行
.beanFilter(ArtCrowd::isDance) // bean过滤
.read(path.toFile());//
另外,MyExcel一直在实际生产环境中使用,每天导出、读取Excel接近上亿数据,内存占用、抖动极低,足够应对绝大部分应用场景。
本次更新为功能增强:
- 支持jfinal的enjoy模板引擎;
- 支持velocity模板引擎;
- 设置模板导出默认宽度策略为计算自动宽度策略,平衡导出时间与样式展示;
截止目前,MyExcel已支持主流的6种模板引擎,相信应该满足大部分同学构建复杂Excel的需求。
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>2.7.23</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-templates</artifactId>
<version>2.4.13</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>enjoy</artifactId>
<version>4.8</version>
</dependency>
如上述模板引擎仍不满足,可在issue中提出,会尽快提供!
使用文档,请移步:myexcel文档
SpringBoot 使用 velocity 模板引擎
最爽的 Web 组合开发就是 Intellij IDEA + Maven + Spring Boot + Scala + Velocity + Boostrap + jQuery 了.
Spring Boot 提供了一个强大的一键式 Spring 的集成开发环境,能够单独进行一个 Spring 应用的开发,其中:
(1)集中式配置(application.properties)+ 注解,大大简化了开发流程
(2)内嵌的 Tomcat 和 Jetty 容器,可直接打成 jar 包启动,无需提供 Java war 包以及繁琐的 Web 配置
(3)提供了 Spring 各个插件的基于 Maven 的 pom 模板配置,开箱即用,便利无比。
(4)可以在任何你想自动化配置的地方,实现可能
(5)提供更多的企业级开发特性,如何系统监控,健康诊断,权限控制
(6)无冗余代码生成和 XML 强制配置
(7)提供支持强大的 Restfult 风格的编码,非常简洁
当然 Spring Boot 提供的功能,远远比上面的强大. Spring boot 集成了 servlet 容器,当我们在 pom 文件中增加 spring-boot-starter-web 的 maven 依赖时,不做任何 web 相关的配置便能提供 web 服务,这还得归于 spring boot 自动配置的功能(因为加了 EnableAutoConfiguration 的注解),帮我们创建了一堆默认的配置,以前在 web.xml 中配置,现在都可以通过 spring bean 的方式进行配置,由 spring 来进行生命周期的管理,大多数情况下,我们需要重载这些配置(例如修改服务的启动端口,contextpath,filter,listener,servlet,session 超时时间等)
本章我们介绍一下,在 SB 中使用模板引擎 Velocity.
##SB 默认支持的模板引擎
spring boot 会自动配置 FreeMarker,Thymeleaf,Velocity,只需要在 pom 中加入相应的依赖即可
##SB 使用 Velocity 的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
默认配置下 spring boot 会从 src/main/resources/templates 目录中去找模板
##SB 的 velocity 配置
###application.properties 配置
lightsword/src/main/resources/application.properties
# VELOCITY TEMPLATES (VelocityAutoConfiguration)
spring.velocity.charset=UTF-8
spring.velocity.properties.input.encoding=UTF-8
spring.velocity.properties.output.encoding=UTF-8
spring.velocity.resourceLoaderPath=classpath:/templates/
spring.velocity.suffix=.html
spring.velocity.toolbox-config-location=/WEB-INF/toolbox.xml
这样,SB 会从 src/main/resources/templates 目录中去找以.html 后缀的模板文件.
###Controller 里面的 Model
数据 httpapis 通过 model 传到模板文件 (SpringMVC 框架里面做的事情):
model.addAttribute("httpapis", HttpApiDao.findAll())
完整的 Controller 代码:
https://github.com/LightSwordSpringBoot/lightsword/blob/lightsword/src/main/scala/com/springboot/in/action/controller/HttpApiController.scala
package com.springboot.in.action.controller
import java.util.Date
import java.util.concurrent.CountDownLatch
import com.alibaba.fastjson.JSON
import com.springboot.in.action.dao.{HttpApiDao, HttpReportDao, HttpSuiteDao}
import com.springboot.in.action.engine.OkHttp
import com.springboot.in.action.entity.{HttpApi, HttpReport}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod, RequestParam, ResponseBody, RestController}
import org.springframework.web.servlet.ModelAndView
import scala.collection.JavaConversions._
@RestController
@RequestMapping(Array("/httpapi"))
class HttpApiController @Autowired() (
val HttpSuiteDao: HttpSuiteDao,
val HttpApiDao: HttpApiDao,
val HttpReportDao: HttpReportDao) {
@RequestMapping(value = {
Array("", "/")
}, method = Array(RequestMethod.GET))
def list(model: Model) = {
model.addAttribute("httpapis", HttpApiDao.findAll())
new ModelAndView("/httpapi/list")
}
...
}
### 模板文件 list.html
lightsword/src/main/resources/templates/httpapi/list.html
#include("/common/header.html")
<div class="form-group">
<table style="word-break: break-all; word-wrap: break-all;"
class="table table-hover table-condensed table-responsive">
<thead>
<tr>
<th style=''width: 60px''>Id</th>
<th style=''width: 100px''>用例名称</th>
<th>URL</th>
<th style=''width: 80px''>方法</th>
<th style=''width: 100px''>期望输出</th>
<th style=''width: 60px''>次数</th>
<th>状态</th>
<th style=''width: 90px''>创建人</th>
<th style=''width: 120px''>调用时间</th>
<th style=''width: 60px''>操作</th>
<th>执行测试</th>
</tr>
</thead>
<tbody>
#foreach ($t in $httpapis)
<tr>
<td>$!t.id</td>
<td>$!t.name</td>
<td>$!t.url</td>
<td>$!t.method</td>
<td>$!t.expectOutput</td>
<td>$!t.runTimes</td> #if($!t.state==1)
<td><div class="btn btn-success">成功</div></td> #elseif($!t.state==0)
<td><div class="btn btn-danger">失败</div></td> #else
<td><div class="btn btn-info">未执行</div></td> #end
<td>$!t.owner</td>
<td>$!DateTool.format(''yyyy-MM-dd HH:mm:ss'', $!t.gmtModify)</td>
<td><a href="/httpapi/detailPage/$t.id">查看</a></td>
<td><div id=''btn-$t.id'' class=''btn btn-primary''
onclick=''runTest($t.id)''>运行</div></td>
</tr>
#end
</tbody>
</table>
</div>
<script>
function runTest(id) {
var url = ''/httpapi/runTest?id='' + id
$.getJSON(url, function(data) {
if (data) {
alert(''响应结果:'' + JSON.stringify(data, null, 2))
location.reload()
} else {
alert(''执行失败'')
}
})
}
</script>
#include("/common/footer.html")
velocity 的语法详情参考:
##toolbox 的使用
我们在 velocity 模板文件中有时候需要格式化小数点,日期等输出,我们可以使用 toolbox.
我们看到 application.properties 有这么一行配置:
spring.velocity.toolbox-config-location=/WEB-INF/toolbox.xml
然后,在 list.html 里面有这么一行代码
<td>$!DateTool.format(''yyyy-MM-dd HH:mm:ss'', $!t.gmtModify)</td>
这个 DateTool 就是我们这里要说的 toolbox 的功能.
lightsword/src/main/resources/WEB-INF/toolbox.xml 的配置如下
<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================= @(#) toolbox.xml
Copyright (c) 2016, Project, All Rights Reserved. ============================================================= -->
<toolbox>
<!-- [ DateTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/generic/DateTool.html
(ja) @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>DateTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
<!-- [ MathTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/generic/MathTool.html
(ja) @see http://velocity.apache.org/tools/devel/generic/MathTool.html (en)
@since VelocityTools 1.0 -->
<tool>
<key>MathTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
<!-- [ NumberTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/NumberTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>NumberTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.NumberTool</class>
</tool>
<!-- [ RenderTool ] @see http://velocity.apache.org/tools/devel/generic/RenderTool.html
(en) @since VelocityTools 1.0 <tool> <key>render</key> <scope>application</scope>
<class>org.apache.velocity.tools.generic.RenderTool</class> </tool> -->
<!-- [ EscapeTool ] @see http://velocity.apache.org/tools/devel/generic/EscapeTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>EscapeTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
<!-- [ ResourceTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ResourceTool.html
(en) @since Velocity 1.3 <tool> <key>text</key> <class>org.apache.velocity.tools.generic.ResourceTool</class>
<parameter name="bundles" value="resources,prj.hoboken.patrasche.resources.PatrascheResources"
/> <parameter name="locale" value="ja_JP" /> </tool> -->
<!-- [ AlternatorTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/AlternatorTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>AlternatorTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.AlternatorTool</class>
</tool>
<!-- [ ValueParser ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ValueParser.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>ValueParser</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ValueParser</class>
</tool>
<!-- [ ListTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ListTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>ListTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ListTool</class>
</tool>
<!-- [ SortTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>SortTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.SortTool</class>
</tool>
<!-- [ IteratorTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/IteratorTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>IteratorTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.generic.IteratorTool</class>
</tool>
<!-- ============================================================ [ TOOL
FOR STRUTS TAGLIB ] ============================================================ -->
<!-- [ ActionMessagesTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/ActionMessagesTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/ActionMessagesTool.html
(en) @since VelocityTools 1.1 -->
<tool>
<key>ActionMessagesTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ActionMessagesTool</class>
</tool>
<!-- [ ErrorsTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/ErrorsTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/ErrorsTool.html (en)
@since VelocityTools 1.0 -->
<tool>
<key>ErrorsTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ErrorsTool</class>
</tool>
<!-- [ FormTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/FormTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/FormTool.html (en)
@since VelocityTools 1.0 -->
<tool>
<key>FormTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.FormTool</class>
</tool>
<!-- [ MessageTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/MessageTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/MessageTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>MessageTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
<!-- [ StrutsLinkTool ] LinkTool @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/StrutsLinkTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/StrutsLinkTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>StrutsLinkTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
</tool>
<!-- [ SecureLinkTool ] LinkTool @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/SecureLinkTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/SecureLinkTool.html
(en) @since VelocityTools 1.1 -->
<tool>
<key>SecureLinkTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.SecureLinkTool</class>
</tool>
<!-- [ TilesTool ] Tiles @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/TilesTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/TilesTool.html (en)
@since VelocityTools 1.1 -->
<tool>
<key>TilesTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.TilesTool</class>
</tool>
<!-- [ ValidatorTool ] Validator @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/ValidatorTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/ValidatorTool.html
(en) @since VelocityTools 1.1 -->
<tool>
<key>ValidatorTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ValidatorTool</class>
</tool>
</toolbox>
这样我们就可以在模板文件中使用类似 DateTool 这样的工具类了。同时我们也可以在代码里自己实现工具类,然后配置到 toolbox.xml 文件里.
新书上架:《Spring Boot 开发实战》
— 基于 Kotlin + Gradle + Spring Boot 2.0 的企业级服务端开发实战
京东下单链接
https://item.jd.com/31178320122.html
天猫下单链接
https://detail.tmall.com/item.htm?id=574928877711
Springboot使用velocity模板引擎
第五章 使用velocity模板引擎
最爽的Web组合开发就是Intellij IDEA + Maven + Spring Boot + Scala + Velocity + Boostrap + jQuery了.
Spring Boot提供了一个强大的一键式Spring的集成开发环境,能够单独进行一个Spring应用的开发,其中:
(1)集中式配置(application.properties)+注解,大大简化了开发流程
(2)内嵌的Tomcat和Jetty容器,可直接打成jar包启动,无需提供Java war包以及繁琐的Web配置
(3)提供了Spring各个插件的基于Maven的pom模板配置,开箱即用,便利无比。
(4)可以在任何你想自动化配置的地方,实现可能
(5)提供更多的企业级开发特性,如何系统监控,健康诊断,权限控制
(6)无冗余代码生成和XML强制配置
(7)提供支持强大的Restfult风格的编码,非常简洁
当然Spring Boot提供的功能,远远比上面的强大. Spring boot集成了servlet容器,当我们在pom文件中增加spring-boot-starter-web的maven依赖时,不做任何web相关的配置便能提供web服务,这还得归于spring boot 自动配置的功能(因为加了EnableAutoConfiguration的注解),帮我们创建了一堆默认的配置,以前在web.xml中配置,现在都可以通过spring bean的方式进行配置,由spring来进行生命周期的管理,大多数情况下,我们需要重载这些配置(例如修改服务的启动端口,contextpath,filter,listener,servlet,session超时时间等)
本章我们介绍一下,在SB中使用模板引擎Velocity.
SB默认支持的模板引擎
spring boot会自动配置 FreeMarker,Thymeleaf,Velocity,只需要在pom中加入相应的依赖即可
SB使用Velocity的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
默认配置下spring boot会从src/main/resources/templates目录中去找模板
SB的velocity配置
application.properties配置
lightsword/src/main/resources/application.properties
# VELOCITY TEMPLATES (VelocityAutoConfiguration)
spring.velocity.charset=UTF-8
spring.velocity.properties.input.encoding=UTF-8
spring.velocity.properties.output.encoding=UTF-8
spring.velocity.resourceLoaderPath=classpath:/templates/
spring.velocity.suffix=.html
spring.velocity.toolbox-config-location=/WEB-INF/toolbox.xml
这样,SB会从src/main/resources/templates目录中去找以.html后缀的模板文件.
Controller里面的Model
数据httpapis通过model传到模板文件(SpringMVC框架里面做的事情):
model.addAttribute("httpapis", HttpApiDao.findAll())
完整的Controller代码:
https://github.com/LightSwordSpringBoot/lightsword/blob/lightsword/src/main/scala/com/springboot/in/action/controller/HttpApiController.scala
package com.springboot.in.action.controller
import java.util.Date
import java.util.concurrent.CountDownLatch
import com.alibaba.fastjson.JSON
import com.springboot.in.action.dao.{HttpApiDao, HttpReportDao, HttpSuiteDao}
import com.springboot.in.action.engine.OkHttp
import com.springboot.in.action.entity.{HttpApi, HttpReport}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod, RequestParam, ResponseBody, RestController}
import org.springframework.web.servlet.ModelAndView
import scala.collection.JavaConversions._
@RestController
@RequestMapping(Array("/httpapi"))
class HttpApiController @Autowired() (
val HttpSuiteDao: HttpSuiteDao,
val HttpApiDao: HttpApiDao,
val HttpReportDao: HttpReportDao) {
@RequestMapping(value = {
Array("", "/")
}, method = Array(RequestMethod.GET))
def list(model: Model) = {
model.addAttribute("httpapis", HttpApiDao.findAll())
new ModelAndView("/httpapi/list")
}
...
}
模板文件list.html
lightsword/src/main/resources/templates/httpapi/list.html
#include("/common/header.html")
<div>
<table>
<thead>
<tr>
<thwidth: 60px''>Id</th>
<thwidth: 100px''>用例名称</th>
<th>URL</th>
<thwidth: 80px''>方法</th>
<thwidth: 100px''>期望输出</th>
<thwidth: 60px''>次数</th>
<th>状态</th>
<thwidth: 90px''>创建人</th>
<thwidth: 120px''>调用时间</th>
<thwidth: 60px''>操作</th>
<th>执行测试</th>
</tr>
</thead>
<tbody>
#foreach ($t in $httpapis)
<tr>
<td>$!t.id</td>
<td>$!t.name</td>
<td>$!t.url</td>
<td>$!t.method</td>
<td>$!t.expectOutput</td>
<td>$!t.runTimes</td> #if($!t.state==1)
<td><div>成功</div></td> #elseif($!t.state==0)
<td><div>失败</div></td> #else
<td><div>未执行</div></td> #end
<td>$!t.owner</td>
<td>$!DateTool.format(''yyyy-MM-dd HH:mm:ss'', $!t.gmtModify)</td>
<td><a href="/httpapi/detailPage/$t.id">查看</a></td>
<td><div id=''btn-$t.id''btn btn-primary''
onclick=''runTest($t.id)''>运行</div></td>
</tr>
#end
</tbody>
</table>
</div>
<script>
function runTest(id) {
var url = ''/httpapi/runTest?id='' + id
$.getJSON(url, function(data) {
if (data) {
alert(''响应结果:'' + JSON.stringify(data, null, 2))
location.reload()
} else {
alert(''执行失败'')
}
})
}
</script>
#include("/common/footer.html")
velocity的语法详情参考:
toolbox的使用
我们在velocity模板文件中有时候需要格式化小数点,日期等输出,我们可以使用toolbox.
我们看到application.properties有这么一行配置:
spring.velocity.toolbox-config-location=/WEB-INF/toolbox.xml
然后,在list.html里面有这么一行代码
<td>$!DateTool.format(''yyyy-MM-dd HH:mm:ss'', $!t.gmtModify)</td>
这个DateTool就是我们这里要说的toolbox的功能.
lightsword/src/main/resources/WEB-INF/toolbox.xml的配置如下
<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================= @(#) toolbox.xml
Copyright (c) 2016, Project, All Rights Reserved. ============================================================= -->
<toolbox>
<!-- [ DateTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/generic/DateTool.html
(ja) @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>DateTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
<!-- [ MathTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/generic/MathTool.html
(ja) @see http://velocity.apache.org/tools/devel/generic/MathTool.html (en)
@since VelocityTools 1.0 -->
<tool>
<key>MathTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
<!-- [ NumberTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/NumberTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>NumberTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.NumberTool</class>
</tool>
<!-- [ RenderTool ] @see http://velocity.apache.org/tools/devel/generic/RenderTool.html
(en) @since VelocityTools 1.0 <tool> <key>render</key> <scope>application</scope>
<class>org.apache.velocity.tools.generic.RenderTool</class> </tool> -->
<!-- [ EscapeTool ] @see http://velocity.apache.org/tools/devel/generic/EscapeTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>EscapeTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
<!-- [ ResourceTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ResourceTool.html
(en) @since Velocity 1.3 <tool> <key>text</key> <class>org.apache.velocity.tools.generic.ResourceTool</class>
<parameter name="bundles" value="resources,prj.hoboken.patrasche.resources.PatrascheResources"
/> <parameter name="locale" value="ja_JP" /> </tool> -->
<!-- [ AlternatorTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/AlternatorTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>AlternatorTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.AlternatorTool</class>
</tool>
<!-- [ ValueParser ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ValueParser.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>ValueParser</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ValueParser</class>
</tool>
<!-- [ ListTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/ListTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>ListTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ListTool</class>
</tool>
<!-- [ SortTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/SortTool.html
(en) @since VelocityTools 1.2 -->
<tool>
<key>SortTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.SortTool</class>
</tool>
<!-- [ IteratorTool ] @see http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/IteratorTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>IteratorTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.generic.IteratorTool</class>
</tool>
<!-- ============================================================ [ TOOL
FOR STRUTS TAGLIB ] ============================================================ -->
<!-- [ ActionMessagesTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/ActionMessagesTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/ActionMessagesTool.html
(en) @since VelocityTools 1.1 -->
<tool>
<key>ActionMessagesTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ActionMessagesTool</class>
</tool>
<!-- [ ErrorsTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/ErrorsTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/ErrorsTool.html (en)
@since VelocityTools 1.0 -->
<tool>
<key>ErrorsTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ErrorsTool</class>
</tool>
<!-- [ FormTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/FormTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/FormTool.html (en)
@since VelocityTools 1.0 -->
<tool>
<key>FormTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.FormTool</class>
</tool>
<!-- [ MessageTool ] @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/MessageTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/MessageTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>MessageTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
<!-- [ StrutsLinkTool ] LinkTool @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/StrutsLinkTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/StrutsLinkTool.html
(en) @since VelocityTools 1.0 -->
<tool>
<key>StrutsLinkTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
</tool>
<!-- [ SecureLinkTool ] LinkTool @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/SecureLinkTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/SecureLinkTool.html
(en) @since VelocityTools 1.1 -->
<tool>
<key>SecureLinkTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.SecureLinkTool</class>
</tool>
<!-- [ TilesTool ] Tiles @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/TilesTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/TilesTool.html (en)
@since VelocityTools 1.1 -->
<tool>
<key>TilesTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.TilesTool</class>
</tool>
<!-- [ ValidatorTool ] Validator @see http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs-ja/struts/ValidatorTool.html
(ja) @see http://velocity.apache.org/tools/devel/struts/ValidatorTool.html
(en) @since VelocityTools 1.1 -->
<tool>
<key>ValidatorTool</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ValidatorTool</class>
</tool>
</toolbox>
这样我们就可以在模板文件中使用类似DateTool这样的工具类了.同时我们也可以在代码里自己实现工具类,然后配置到toolbox.xml文件里.
关于【软件周刊第 41 期】模板引擎 Velocity Engine 发布 2.0 版本;Bootstrap 4 首个 Beta 版发布的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于End Admin beta 测试版发布,基于 bootstrap 3.2 的后台模版、MyExcel 3.3.2 版本发布,velocity&enjoy 模板引擎支持、SpringBoot 使用 velocity 模板引擎、Springboot使用velocity模板引擎的相关信息,请在本站寻找。
本文标签: