Freemarker Built-ins for booleans

本文介绍如何使用FreeMarker将布尔值转换成字符串的方法。包括使用默认的字符串表示形式和自定义true/false对应的字符串。这在生成源代码时特别有用,因为值不会受到地区设置的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Built-ins for booleans

string (when used with a boolean value)

Converts a boolean to a string. You can use it in two ways:

  • As foo?string: This will convert the boolean to string using the default strings for representing true and false values. By default, true is rendered as "true" and false is rendered as "false". This is mostly useful if you generate source code with FreeMarker, since the values are not locale (language, country) sensitive. To change these default strings, you can use the boolean_format setting. Note, that if the variable is multi-type variable that is both boolean and string, then the string value of the variable will be returned.

  • As foo?string("yes", "no"): This will return the first parameter (here: "yes") if the boolean is true, otherwise the second parameter (here: "no"). Note that the return value is always a string; if the parameters were numbers, they would be converted to strings first.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值