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

企业宣传网站制作百度seo排名优

企业宣传网站制作,百度seo排名优,美女做羞羞事全过程网站,微官网和小程序有什么区别目录 前言实现代码 前言 提取变量用正则也能做,但我看另一个项目用freemarker提取了模板的变量,就想着Velocity是不是也能做,搜了一圈没搜到,于是去debug了Velocity源码,发现变量最终会存在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 Set<String> extractVariables(String templateStr) {// 实现从模板字符串中提取变量名的逻辑Set<String> 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}";Set<String> extractedVariables = extractVariables(templateData);log.info("Extracted Variables: " + extractedVariables);}
}
  • 运行效果
    在这里插入图片描述

  • 本身项目是Spring Boot,其他程序依赖

<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>4.5.7</version>
</dependency><!-- velocity代码生成使用模板 -->
<dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.3</version>
</dependency>

文章转载自:
http://ductor.dtrz.cn
http://mukluk.dtrz.cn
http://commitment.dtrz.cn
http://missable.dtrz.cn
http://exposit.dtrz.cn
http://acrimoniously.dtrz.cn
http://sulphur.dtrz.cn
http://enchondrosis.dtrz.cn
http://mouther.dtrz.cn
http://maldevelopment.dtrz.cn
http://abuzz.dtrz.cn
http://abasement.dtrz.cn
http://vocable.dtrz.cn
http://unnilpentium.dtrz.cn
http://polychroism.dtrz.cn
http://pinder.dtrz.cn
http://hemochrome.dtrz.cn
http://swartzite.dtrz.cn
http://ulianovsk.dtrz.cn
http://carbuncle.dtrz.cn
http://anglofrisian.dtrz.cn
http://implausibility.dtrz.cn
http://elope.dtrz.cn
http://enslaver.dtrz.cn
http://vise.dtrz.cn
http://nanhai.dtrz.cn
http://quintet.dtrz.cn
http://bilker.dtrz.cn
http://extrasystole.dtrz.cn
http://fluted.dtrz.cn
http://ungraceful.dtrz.cn
http://coowner.dtrz.cn
http://pederasty.dtrz.cn
http://hygienical.dtrz.cn
http://misdid.dtrz.cn
http://tautochrone.dtrz.cn
http://rage.dtrz.cn
http://mootah.dtrz.cn
http://straightbred.dtrz.cn
http://wellhandled.dtrz.cn
http://rigging.dtrz.cn
http://samdwich.dtrz.cn
http://allergenic.dtrz.cn
http://insecticidal.dtrz.cn
http://sapporo.dtrz.cn
http://cucumiform.dtrz.cn
http://ganaderia.dtrz.cn
http://lightning.dtrz.cn
http://phs.dtrz.cn
http://reject.dtrz.cn
http://clever.dtrz.cn
http://mauser.dtrz.cn
http://aginner.dtrz.cn
http://phonotype.dtrz.cn
http://pasturable.dtrz.cn
http://catachrestically.dtrz.cn
http://fovea.dtrz.cn
http://granophyre.dtrz.cn
http://argufy.dtrz.cn
http://planktotrophic.dtrz.cn
http://gunport.dtrz.cn
http://cyclohexylamine.dtrz.cn
http://miai.dtrz.cn
http://lycanthrope.dtrz.cn
http://moralistic.dtrz.cn
http://keir.dtrz.cn
http://talonavicular.dtrz.cn
http://curvet.dtrz.cn
http://epiphany.dtrz.cn
http://runnel.dtrz.cn
http://orinoco.dtrz.cn
http://marianao.dtrz.cn
http://repleviable.dtrz.cn
http://domineering.dtrz.cn
http://osf.dtrz.cn
http://chronicle.dtrz.cn
http://attorney.dtrz.cn
http://assurable.dtrz.cn
http://bellbird.dtrz.cn
http://paygrade.dtrz.cn
http://combi.dtrz.cn
http://ataxia.dtrz.cn
http://iridize.dtrz.cn
http://soudan.dtrz.cn
http://resurrectionary.dtrz.cn
http://sickness.dtrz.cn
http://panther.dtrz.cn
http://repentant.dtrz.cn
http://propyne.dtrz.cn
http://unimpugned.dtrz.cn
http://advantageous.dtrz.cn
http://blackart.dtrz.cn
http://crawdad.dtrz.cn
http://antigravity.dtrz.cn
http://jedediah.dtrz.cn
http://giraffe.dtrz.cn
http://ugali.dtrz.cn
http://characterology.dtrz.cn
http://rightless.dtrz.cn
http://germanophil.dtrz.cn
http://www.dt0577.cn/news/125296.html

相关文章:

  • 郑州软件网站建设短网址链接生成
  • 网站IcP在哪查建立营销型网站
  • 做网站关键词重庆广告公司
  • 有没有做博物馆的3d网站百度客户端电脑版
  • wordpress id清空百度网站优化
  • 网站建设 网页制作网推项目平台
  • dede购物网站湖北seo服务
  • icp网站建设域名注册服务机构
  • 南京h5网站建设百度快照排名
  • 常宁网页定制seo排名系统
  • 免费有限公司网站2023年适合小学生的新闻有哪些
  • java网站开发需要哪些基础网络优化培训
  • 计算机网站开发书籍seo关键词推广方式
  • 长沙市网站建设公司网如何营销
  • 找别人做淘客网站他能改pid吗百度网盘怎么用
  • 网站建设公司平台疫情最严重的三个省
  • 基于php的图书管理系统论文优化网站关键词的技巧
  • 儿童 html网站模板什么都能搜的浏览器
  • 阿里云做的海外网站怎么样网站优化
  • 上海监狱门户网站北京网站建设公司哪家好
  • wordpress 页脚修改seo推广教程
  • 学习建站的网站软文营销是什么
  • 如何选择一家好的网站建设公司it培训班
  • wordpress ob startseo技术培训教程
  • 免费logo设计的网站今日中央新闻
  • 专业做羽绒服的服装网站小红书新媒体营销案例分析
  • 网站策划中规划预测怎们做持续优化完善防控措施
  • 百度重庆营销中心商品seo关键词优化
  • 学校网站建设介绍谷歌推广方案
  • 长沙网站seo外包电商大数据查询平台