java之注释语法

1. 快速入门之无序列表

/**
     * 这是一个用户登录方法
     * <h1>你要遵循以下几点要求</h1>
     * <ul>
     *   <li>雪碧</li>
     *   <li>可乐</li>
     *   <li>凉茶</li>
     * </ul>
     */
    public void login(){
    
    
        System.out.println("jaja ");
}

@Autowired
	UserService userService;

	@GetMapping("/")
	public void test(){
    
    
		userService.login();
	}

在这里插入图片描述

2. pre标签

  我们经常会在要保持文本格式的时候使用pre标签,比如当我们要展示源代码的时候,只要放一个pre标签,然后把源代码直接复制,粘贴,然后在页面上就可以保持好格式。不会像放在其它标签里那样,把换行和空格都自动折叠了。这里看一下pre是如何工作的呢?

HTML里的pre元素,可定义预格式化的文本。在pre元素中的文本会保留空格和换行符。文本显现为等宽字体。

下面我们看一个示例,这里我使用的是一段css代码,你也可以换成其它的。如下:

body{
    
    
    background:#fff;
      font: 12px/24px 1.66;
}

当我们用pre包裹它们时

<pre>
body{
    
    
    background:#fff;
      font: 12px/24px 1.66;
}
</pre>

会在浏览器上直接得到(注释原理一样)

在这里插入图片描述

可以看出上面的tab,空格,换行都完整的保留下来了。

3. lt和gt

lt 是less than的首字母缩写
gt 是greater than的首字母缩写

在 HTML 中,某些字符是预留的。
在 HTML 中不能使用小于号(<)和大于号(>),这是因为浏览器会误认为它们是标签。
如果希望正确地显示预留字符,我们必须在 HTML 源代码中使用字符实体

如需显示小于号,我们必须这样写:

在这里插入图片描述

/*
* <pre>
	 * &lt;c:url value="/login" var="loginProcessingUrl"/&gt;
	 * &lt;form action="${loginProcessingUrl}" method="post"&gt;
	 *    &lt;fieldset&gt;
	 *        &lt;legend&gt;Please Login&lt;/legend&gt;
	 *                &lt;c:if test="${SPRING_SECURITY_LAST_EXCEPTION != null}"&gt;
	 *                  Reason: &lt;c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" /&gt;
	 *                &lt;/c:if&gt;
	 *            &lt;/div&gt;
	 *        &lt;/c:if&gt;
	 *        &lt;c:if test="${param.logout != null}"&gt;
	 *            &lt;div&gt;
	 *                You have been logged out.
	 *            &lt;/div&gt;
	 *        &lt;/c:if&gt;
	 *        &lt;p&gt;
	 *        &lt;label for="username"&gt;Username&lt;/label&gt;
	 *        &lt;input type="text" id="username" name="username"/&gt;
	 *        &lt;/p&gt;
	 *        &lt;p&gt;
	 *        &lt;label for="password"&gt;Password&lt;/label&gt;
	 *        &lt;input type="password" id="password" name="password"/&gt;
	 *        &lt;/p&gt;
	 *        &lt;p&gt;
	 *        &lt;label for="remember-me"&gt;Remember Me?&lt;/label&gt;
	 *        &lt;input type="checkbox" id="remember-me" name="remember-me"/&gt;
	 *        &lt;/p&gt;
	 *        &lt;div&gt;
	 *            &lt;button type="submit" class="btn"&gt;Log in&lt;/button&gt;
	 *        &lt;/div&gt;
	 *    &lt;/fieldset&gt;
	 * &lt;/form&gt;
	 * </pre>
	 *
	 * <h2>Impact on other defaults</h2>
	 *
	 * Updating this value, also impacts a number of other default values. For example,
	 * the following are the default values when only formLogin() was specified.
	 *
	 * <ul>
	 * <li>/login GET - the login form</li>
	 * <li>/login POST - process the credentials and if valid authenticate the user</li>
	 * <li>/login?error GET - redirect here for failed authentication attempts</li>
	 * <li>/login?logout GET - redirect here after successfully logging out</li>
	 * </ul>
	 *
	 * If "/authenticate" was passed to this method it update the defaults as shown below:
	 *
	 * <ul>
	 * <li>/authenticate GET - the login form</li>
	 * <li>/authenticate POST - process the credentials and if valid authenticate the user
	 * </li>
	 * <li>/authenticate?error GET - redirect here for failed authentication attempts</li>
	 * <li>/authenticate?logout GET - redirect here after successfully logging out</li>
	 * </ul>
	 */

4. {@link}与@see

写代码的时候,有时候,你需要写一些注释,把内容相互关联起来,方便自己或别人看的时候,可以直接找到你关联的代码类或者啥的。
这个时候,{@link}与@see,这2个javadoc注解就派上用场了,
不管他具体有什么功能,咱就只管一个,他可以链接代码,让注释看的更清楚易懂。方便你我他。

@see 标签允许用户引用其他类的文档。具体使用方式如下:
@see classname
@see fully-qualified-classname
@see fully-qualified-classname#方法名称
@see fully-qualified-classname#属性名称

我在使用的时候,发现这个只能单独一行顶头写,如果不顶头写就不管用了,没了链接的效果。
但是,{@link}这个却可以随便放。
具体使用方法和上面那个@see是一样的。
实际效果,看下面的图吧。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43088443/article/details/112999886