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

SpringBoot整合Freemarker(二)

if分支

语法:

<#if condition>...
<#elseif condition2>...
<#elseif condition3>...
<#else>...
</#if>

例子:

<#if x = 1>x is 1
</#if>
---------------------------------
<#if x = 1>x is 1
<#else>x is not 1
</#if>

switch分支

语法:

<#switch value><#case refValue1>...<#break><#case refValue2>...<#break><#case refValueN>...<#break><#default>...
</#switch>

例子:

<#switch cloth.size>  // 这里的变量类型可以是字符串也可是整数<#case "small">This will be processed if it is small<#break><#case "medium">This will be processed if it is medium<#break><#case "large">This will be processed if it is large<#break><#default>This will be processed if it is neither
</#switch>

list循环

<#list sequence as item>
...
<#if item = "spring"><#break></#if>
...
</#list>

例子:

<#assign seq = ["winter", "spring", "summer", "autumn"]> // assign 定义一个变量,这里定义了一个数组
<#list seq as x>   // list循环遍历这个数组${x_index + 1}. ${x}<#if x_has_next>,</#if>
</#list>

关键字:

item_index:是list当前值的下标,从0开始item_has_next:判断list是否还有值

macro, nested, return

语法

<#macro name param1 param2 ... paramN> ...<#nested loopvar1, loopvar2, ..., loopvarN>  //有了这和标签:调用宏的时候,必须用双标签...<#return>...
</#macro>

用例

<#macro test foo bar="Bar"  baaz=-1>Test text, and the params: ${foo}, ${bar}, ${baaz}
</#macro><@test foo="a" bar="b" baaz=5*5-2/>
<@test foo="a" bar="b"/>
<@test foo="a" baaz=5*5-2/>
<@test foo="a"/> 
输出Test text, and the params: a, b, 23Test text, and the params: a, b, -1Test text, and the params: a, Bar, 23Test text, and the params: a, Bar, -1
http://www.lryc.cn/news/478990.html

相关文章:

  • element plus el-form自定义验证输入框为纯数字函数
  • Android笔记(三十一):Deeplink失效问题
  • 图神经网络初步实验
  • 创建线程时传递参数给线程
  • 兴业严选|美国总统都是不良资产出身 法拍市场是否将大众化
  • C#-拓展方法
  • 加锁失效,非锁之过,加之错也|京东零售供应链库存研发实践
  • vue3 传值的几种方式
  • AUTOSAR CP NVRAM Manager规范导读
  • 2024阿里云CTF Web writeup
  • 软件著作权申请教程(超详细)(2024新版)软著申请
  • 三维测量与建模笔记 - 3.2 直接线性变换法标定DLT
  • Whisper AI视频(音频)转文本
  • 全网最详细RabbitMQ教学包括如何安装环境【RabbitMQ】RabbitMQ + Spring Boot集成零基础入门(基础篇)
  • esp32记录一次错误
  • Moonshine - 新型开源ASR(语音识别)模型,体积小,速度快,比OpenAI Whisper快五倍 本地一键整合包下载
  • java-web-苍穹外卖-day1:软件开发步骤简化版+后端环境搭建
  • 一个国产 API 开源项目,在 ProductHunt 杀疯了...
  • 斗破QT编程入门系列之二:认识Qt:编写一个HelloWorld程序(四星斗师)
  • 木马病毒相关知识
  • 用 Python 写了一个天天酷跑(附源码)
  • 【网络-交换机】生成树协议、环路检测
  • C++ 中的 JSON 序列化和反序列化:结构体与枚举类型的处理
  • MySQL 批量删除海量数据的几种方法
  • 【docker入门】docker的安装
  • 单例模式五种写法
  • 解析静态链接
  • 前端基础-html-注册界面
  • 量子电路的实现 基于ibm的qiskit
  • 关于谷歌浏览器debug模式不进断点问题解决方案