你怎么能在javadoc中转义@字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2290757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can you escape the @ character in javadoc?
提问by JayL
How can I escape the @
symbol in javadoc? I am trying to use it inside a {@code}
tag, which is inside <pre>
tags.
如何转义@
javadoc 中的符号?我试图在{@code}
标签内使用它,这是在<pre>
标签内。
I already tried the html escape @
sequence, but that didn't work.
我已经尝试过 html 转义@
序列,但是没有用。
采纳答案by Bohemian
Use the {@literal}
javadoc tag:
使用{@literal}
javadoc 标签:
/**
* This is an "at" symbol: {@literal @}
*/
The javadoc for this will read:
用于此的 javadoc 将显示为:
This is an "at" symbol: @
Of course, this will work for anycharacters, and is the "officially supported" way of displaying any "special" characters.
当然,这适用于任何字符,并且是显示任何“特殊”字符的“官方支持”方式。
It is also the most straighforward - you don't need to know the hex code of the character, andyou can read what you've typed!
这也是最简单明了-你不需要知道字符的十六进制代码,并且可以读取你输入什么!
回答by Yuval Adam
You got the general idea, try using the octal representation: @
你有一个大致的想法,尝试使用八进制表示: @
回答by Frank V
Just write it as an HTML entity:
只需将其编写为 HTML 实体即可:
@
From the document "javadoc - The Java API Documentation Generator"
来自文档“ javadoc - Java API 文档生成器”
If you want to start a line with the @ character and not have it be interpreted, use the HTML entity @.
如果您想以 @ 字符开始一行而不对其进行解释,请使用 HTML 实体 @。
This implies that you can use HTML entities for anycharacter that you would need to escape, and indeed you can:
这意味着您可以将 HTML 实体用于您需要转义的任何字符,实际上您可以:
The text must be written in HTML with HTML entities and HTML tags. You can use whichever version of HTML your browser supports. The standard doclet generates HTML 3.2-compliant code elsewhere (outside of the documentation comments) with the inclusion of cascading style sheets and frames. HTML 4.0 is preferred for generated files because of the frame sets.
For example, entities for the less than symbol (<) and the greater than symbol (>) should be written as
<
and>
. Similarly, the ampersand (&) should be written as&
.
文本必须使用 HTML 实体和 HTML 标签用 HTML 编写。您可以使用浏览器支持的任何 HTML 版本。标准 doclet 在其他地方(文档注释之外)生成符合 HTML 3.2 的代码,包括级联样式表和框架。由于框架集,HTML 4.0 首选用于生成的文件。
例如,小于号 (<) 和大于号 (>) 的实体应写为
<
and>
。同样,与号 (&) 应写为&
.
回答by Yeongjun Kim
my solution is
我的解决方案是
/**
* Mapper Test Helper.
*
* add the following annotations above the class
* <pre>{@code
* // junit5
* @literal @ExtendWith(SpringExtension.class)
* // junit4
* @literal @RunWith(SpringRunner.class)
* }</pre>
*/