当前位置: 首页 > news >正文

网站建设服务专业建站公司什么公司做企业网站

网站建设服务专业建站公司,什么公司做企业网站,电子商务网站多少钱,阅读分享网站模板目录 前言实现代码 前言 提取变量用正则也能做#xff0c;但我看另一个项目用freemarker提取了模板的变量#xff0c;就想着Velocity是不是也能做#xff0c;搜了一圈没搜到#xff0c;于是去debug了Velocity源码#xff0c;发现变量最终会存在Node数组里。 实现代码 … 目录 前言实现代码 前言 提取变量用正则也能做但我看另一个项目用freemarker提取了模板的变量就想着Velocity是不是也能做搜了一圈没搜到于是去debug了Velocity源码发现变量最终会存在Node数组里。 实现代码 我只要能获取到Node [] children数组对象的数据就可以了。 import cn.hutool.core.util.StrUtil; import cn.hutool.extra.template.Template; import cn.hutool.extra.template.engine.velocity.VelocityEngine; import cn.hutool.extra.template.engine.velocity.VelocityTemplate; import com.zbkj.common.constants.Constants; import org.apache.velocity.runtime.parser.node.ASTIdentifier; import org.apache.velocity.runtime.parser.node.ASTReference; import org.apache.velocity.runtime.parser.node.ASTprocess; import org.apache.velocity.runtime.parser.node.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils;import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set;/*** author zzq* description Velocity工具类* date 6/12/2025 14:12:44*/ public class VelocityUtil {private static final Logger log LoggerFactory.getLogger(VelocityUtil.class);private final static String RAW_TEMPLATE_FIELD rawTemplate;/*** 从Velocity模板字符串中提取变量名** param templateStr 模板字符串* return 变量名列表* Date 2025-06-12*/public static SetString extractVariables(String templateStr) {// 实现从模板字符串中提取变量名的逻辑SetString variables new HashSet(Constants.NUM_TWENTY);VelocityEngine engine new VelocityEngine();Template template engine.getTemplate(templateStr);Field rawTemplateField ReflectionUtils.findField(VelocityTemplate.class, RAW_TEMPLATE_FIELD);ReflectionUtils.makeAccessible(rawTemplateField);org.apache.velocity.Template rawTemplate (org.apache.velocity.Template) ReflectionUtils.getField(rawTemplateField, template);ASTprocess rawTemplateData (ASTprocess) rawTemplate.getData();if (!ObjectUtils.isEmpty(rawTemplateData)) {int nodeLength rawTemplateData.jjtGetNumChildren();for (int i 0; i nodeLength; i) {StringBuilder sb new StringBuilder();// 第一级节点Node child rawTemplateData.jjtGetChild(i);if (child instanceof ASTReference) {ASTReference reference (ASTReference) child;String referenceText reference.getRootString();sb.append(referenceText); // log.info(Reference: referenceText);int nodeGrandLen reference.jjtGetNumChildren();// 子孙节点for (int j 0; j nodeGrandLen; j) {Node grandChild reference.jjtGetChild(j);if (grandChild instanceof ASTIdentifier) {ASTIdentifier identifier (ASTIdentifier) grandChild;sb.append(StrUtil.DOT identifier.getIdentifier()); // log.info(Identifier: identifier.getIdentifier());}}variables.add(sb.toString());}}}return variables;}public static void main(String[] args) {// 示例数据String templateData 你是${name} xxx ${java.lang.String.XTEST} ${java.lang} ${STRING};SetString extractedVariables extractVariables(templateData);log.info(Extracted Variables: extractedVariables);} }运行效果 本身项目是Spring Boot其他程序依赖 dependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion4.5.7/version /dependency!-- velocity代码生成使用模板 -- dependencygroupIdorg.apache.velocity/groupIdartifactIdvelocity-engine-core/artifactIdversion2.3/version /dependency
http://www.yayakq.cn/news/5199/

相关文章:

  • jquery网站开发实例高端定制外贸网站
  • 企业网站选wordpress和织梦seo技术代理
  • 做网站主流技术设计参考图网站
  • 怎么做网站代理商无锡企业网站排名优化
  • 网站专题二级页怎么做广西南宁生活网
  • 海淀区企业网站建设thinkphp做网站有什么好处
  • 一手项目对接app平台seo如何选择网站标题
  • 冠辰网站建设网站页面好了怎么做后端
  • 公司网站开发模板建设集团摩托车
  • 深圳企业网站模板重庆市哪个区最繁华
  • wordpress站点字体修改西部数码网站管理助手错误
  • 如何禁止某ip访问网站网站网站建设设计
  • 建设企业网站平台主要的目的是界面设计模式读后感
  • 怎么用php做网站后台程序企业网站 优秀
  • 手机网站设计教育类模板夏天做那些网站致富
  • 旅游网站的设计方案怎么做网站设置密码
  • 徐州做网站xlec网站开发一级分销
  • 电信ip做的网站移动不能访问公司官网开发
  • 做暧暖网站江阳建设集团网站
  • 专业设计网站公司网站建设捌金手指花总四
  • 个人网站制作总体设计蓝色门户网站
  • 怎么给自己公司做网站wordpress开发软件
  • 劲松网站建设公司wordpress做导航站
  • 创新的做pc端网站网站免费视频
  • 在菲做平台网站500强企业网站有哪些
  • 百度网站搜索关键字河北邢台出大事啦
  • 亚马逊没有网站怎么做seo亚马逊雨林动物大全
  • 农产品网站开发背景四会网站建设
  • 网站推广都有哪些公司注册资金可以取出来吗
  • 做网站的公司怎么做业务上海营销型网站开发