java slf4j 占位符_slf4j 占位符

slf4j format 占位符使用{}。

For example,

MessageFormatter.format("Hi {}.", "there")

1

MessageFormatter.format("Hi {}.","there")

will return the string “Hi there.”.

The {} pair is called the formatting anchor. It serves to designate the location where arguments need to be substituted within the message pattern.

In case your message contains the ‘{‘ or the ‘}’ character, you do not have to do anything special unless the ‘}’ character immediately follows ‘{‘. For example,

MessageFormatter.format("Set {1,2,3} is not equal to {}.", "1,2");

1

MessageFormatter.format("Set {1,2,3} is not equal to {}.","1,2");

will return the string “Set {1,2,3} is not equal to 1,2.”.

If for whatever reason you need to place the string “{}” in the message without its formatting anchor meaning, then you need to escape the ‘{‘ character with ‘\’, that is the backslash character. Only the ‘{‘ character should be escaped. There is no need to escape the ‘}’ character. For example,

MessageFormatter.format("Set \\{} is not equal to {}.", "1,2");

1

MessageFormatter.format("Set \\{} is not equal to {}.","1,2");

will return the string “Set {} is not equal to 1,2.”.

The escaping behavior just described can be overridden by escaping the escape character ‘\’. Calling

MessageFormatter.format("File name is C:\\\\{}.", "file.zip");

1

MessageFormatter.format("File name is C:\\\\{}.","file.zip");

官方API https://www.slf4j.org/api/org/slf4j/helpers/MessageFormatter.html

©版权声明:本文为【翰林小院】(huhanlin.com)原创文章,转载时请注明出处!

发布在 2018-06-01 13:50:46

分类:JAVA, JAVA_API

标签:sl4j

发表评论电子邮件地址不会被公开。

评论

姓名

电子邮件

站点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值