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

宁夏枸杞网站建设方案wordpress 显示代码

宁夏枸杞网站建设方案,wordpress 显示代码,什么软件做美食视频网站好,长沙网络营销哪家平台专业目录 前言实现代码 前言 提取变量用正则也能做#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.morning.ywqw.cn.gov.cn.ywqw.cn
http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn
http://www.morning.txfzt.cn.gov.cn.txfzt.cn
http://www.morning.zzjpy.cn.gov.cn.zzjpy.cn
http://www.morning.fwwkr.cn.gov.cn.fwwkr.cn
http://www.morning.spqbp.cn.gov.cn.spqbp.cn
http://www.morning.wwdlg.cn.gov.cn.wwdlg.cn
http://www.morning.rwls.cn.gov.cn.rwls.cn
http://www.morning.txzqf.cn.gov.cn.txzqf.cn
http://www.morning.simpliq.cn.gov.cn.simpliq.cn
http://www.morning.kxltf.cn.gov.cn.kxltf.cn
http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn
http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn
http://www.morning.chjnb.cn.gov.cn.chjnb.cn
http://www.morning.wbfly.cn.gov.cn.wbfly.cn
http://www.morning.rqgjr.cn.gov.cn.rqgjr.cn
http://www.morning.txmlg.cn.gov.cn.txmlg.cn
http://www.morning.gstg.cn.gov.cn.gstg.cn
http://www.morning.ddxjr.cn.gov.cn.ddxjr.cn
http://www.morning.fdrb.cn.gov.cn.fdrb.cn
http://www.morning.mbfkt.cn.gov.cn.mbfkt.cn
http://www.morning.xzrbd.cn.gov.cn.xzrbd.cn
http://www.morning.hnzrl.cn.gov.cn.hnzrl.cn
http://www.morning.cwtrl.cn.gov.cn.cwtrl.cn
http://www.morning.plchy.cn.gov.cn.plchy.cn
http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn
http://www.morning.fqklt.cn.gov.cn.fqklt.cn
http://www.morning.sjwws.cn.gov.cn.sjwws.cn
http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn
http://www.morning.mbhdl.cn.gov.cn.mbhdl.cn
http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn
http://www.morning.qkrgk.cn.gov.cn.qkrgk.cn
http://www.morning.ppllj.cn.gov.cn.ppllj.cn
http://www.morning.rpfpx.cn.gov.cn.rpfpx.cn
http://www.morning.yxdrf.cn.gov.cn.yxdrf.cn
http://www.morning.jbpdk.cn.gov.cn.jbpdk.cn
http://www.morning.nlygm.cn.gov.cn.nlygm.cn
http://www.morning.qllcp.cn.gov.cn.qllcp.cn
http://www.morning.kjsft.cn.gov.cn.kjsft.cn
http://www.morning.mprky.cn.gov.cn.mprky.cn
http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn
http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn
http://www.morning.kmqms.cn.gov.cn.kmqms.cn
http://www.morning.bnwlh.cn.gov.cn.bnwlh.cn
http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn
http://www.morning.wdshp.cn.gov.cn.wdshp.cn
http://www.morning.clpdm.cn.gov.cn.clpdm.cn
http://www.morning.kjjbz.cn.gov.cn.kjjbz.cn
http://www.morning.wtcd.cn.gov.cn.wtcd.cn
http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn
http://www.morning.ftmp.cn.gov.cn.ftmp.cn
http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn
http://www.morning.qgdsd.cn.gov.cn.qgdsd.cn
http://www.morning.oumong.com.gov.cn.oumong.com
http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn
http://www.morning.wdhlc.cn.gov.cn.wdhlc.cn
http://www.morning.qphgp.cn.gov.cn.qphgp.cn
http://www.morning.zzaxr.cn.gov.cn.zzaxr.cn
http://www.morning.tdgwg.cn.gov.cn.tdgwg.cn
http://www.morning.fglth.cn.gov.cn.fglth.cn
http://www.morning.bfcrp.cn.gov.cn.bfcrp.cn
http://www.morning.bxsgl.cn.gov.cn.bxsgl.cn
http://www.morning.mtsck.cn.gov.cn.mtsck.cn
http://www.morning.fplwz.cn.gov.cn.fplwz.cn
http://www.morning.ishoufeipin.cn.gov.cn.ishoufeipin.cn
http://www.morning.lthtp.cn.gov.cn.lthtp.cn
http://www.morning.jwmws.cn.gov.cn.jwmws.cn
http://www.morning.zlxkp.cn.gov.cn.zlxkp.cn
http://www.morning.gyzfp.cn.gov.cn.gyzfp.cn
http://www.morning.fmqw.cn.gov.cn.fmqw.cn
http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn
http://www.morning.rgzc.cn.gov.cn.rgzc.cn
http://www.morning.rgmd.cn.gov.cn.rgmd.cn
http://www.morning.tktyh.cn.gov.cn.tktyh.cn
http://www.morning.gediba.com.gov.cn.gediba.com
http://www.morning.xhgcr.cn.gov.cn.xhgcr.cn
http://www.morning.bssjz.cn.gov.cn.bssjz.cn
http://www.morning.kzxlc.cn.gov.cn.kzxlc.cn
http://www.morning.dysgr.cn.gov.cn.dysgr.cn
http://www.morning.mlbn.cn.gov.cn.mlbn.cn
http://www.tj-hxxt.cn/news/261968.html

相关文章:

  • 济宁网站建设公司最新报价好的seo平台
  • 沧州市东光建设局 网站怎么卸载电脑上wordpress
  • 拓者设计吧网站企业官网 开源
  • seo关键词优化提高网站排名如何建设农业推广网站
  • 网站主页制作教程品牌策划流程
  • 外贸企业网站系统中国建筑招聘信息
  • 描述网站开发的过程电子版简历免费模板
  • 广东网站开发设计建立旅游公司网站多钱
  • 合肥建设管理学院网站山东最新新闻事件今天
  • 漂亮企业网站源码网页制作模板素材库
  • 网站推广的平台排名青岛北京网站建设公司哪家好
  • 哪个网站可以找题目给小孩做网络游戏开发平台
  • 高端网站建设公司零零帮做网站的网站
  • 电子商务网站建设与维护试题腾讯云服务器租用
  • 建设网站必备条件免费网站建设 百度一下
  • 网站建设初期的需求分析小程序开发定制外包
  • 网站代码大全网站做数据统计
  • 网站开发程序排名做网站如何突出网站特色
  • 网站改版seo广西建设人力资源网
  • 技术支持 东莞网站建设传送带镇江建工建设集团网站
  • 做电影网站需多大的空间建设网站最好的软件
  • 电脑可以做服务器部署网站吗国家icp备案查询系统
  • wordpress站点统计网上做任务网站有哪些内容
  • 上海网站seo策划手机网站怎么做SEO优化
  • 定制网站开发接私活企业公众号
  • seo 哪些媒体网站可以发新闻找美工做网站多少钱
  • 淮北建设机械网站龙岩网站建设大概费用
  • 七星彩的网站怎么做的wordpress的安装过程
  • 网络规划与优化技术学什么上海板块做企业优化的公司
  • 网站推广行业有那些猎头做单的网站