javadoc是Sun公司提供的一个技术,它从程序源代码中抽取类、方法、成员等注释形成一个和源代码配套的API帮助文档。也就是说,只要在编写程序时以一套特定的标签作注释,在程序编写完成后,通过Javadoc就可以同时形成程序的开发文档了。
如何使用Javadoc:
1.写在类上面的Javadoc
写在类上的文档标注一般分为三段:
第一段:概要描述,通常用一句或者一段话简要描述该类的作用,以英文句号作为结束
第二段:详细描述,通常用一段或者多段话来详细描述该类的作用,一般每段话都以英文句号作为结束
第三段:文档标注,用于标注作者、创建时间、参阅类等信息
package java.lang;
/**
* Class {@code Object} is the root of the class hierarchy.
* Every class has {@code Object} as a superclass. All objects,
* including arrays, implement the methods of this class.
*/
public class Object {}
2.写在方法上的Javadoc
写在方法上的文档标注一般分为三段:
第一段:概要描述,通常用一句或者一段话简要描述该方法的作用,以英文句号作为结束
第二段:详细描述,通常用一段或者多段话来详细描述该方法的作用,一般每段话都以英文句号作为结束
第三段:文档标注,用于标注参数、返回值、异常、参阅等
3.示例
package org.springframework.util;
/**
* Miscellaneous {@link String} utility methods.
*
* <p>Mainly for internal use within the framework; consider
* <a href="http://commons.apache.org/proper/commons-lang/">Apache's Commons Lang</a>
* for a more comprehensive suite of {@code String} utilities.
*
* <p>This class delivers some simple functionality that should really be
* provided by the core Java {@link String} and {@link StringBuilder}
* classes. It also provides easy-to-use methods to convert between
* delimited strings, such as CSV strings, and collections and arrays.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Keith Donald
* @author Rob Harrop
* @author Rick Evans
* @author Arjen Poutsma
* @author Sam Brannen
* @author Brian Clozel
* @since 16 April 2001
*/
public abstract class StringUtils {
/**
* Decode the given encoded URI component value. Based on the following rules:
* <ul>
* <li>Alphanumeric characters {@code "a"} through {@code "z"}, {@code "A"} through {@code "Z"},
* and {@code "0"} through {@code "9"} stay the same.</li>
* <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li>
* <li>A sequence "{@code %<i>xy</i>}" is interpreted as a hexadecimal representation of the character.</li>
* </ul>
*
* @param source the encoded String
* @param charset the character set
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @since 5.0
* @see java.net.URLDecoder#decode(String, String)
*/
public static String uriDecode(String source, Charset charset) {}
package com.example.demo;
/**
* 类 {@code OrderService} 订单服务层.
*
* <p> 主要包括 创建订单、取消订单、查询订单等功能更
*
* @see Order
* @author <a href="mailto:mengday.zhang@gmail.com">Mengday Zhang</a>
* @since 2018/5/12
*/
public class OrderService {
/** 默认数量 {@value} */
private static final Integer QUANTITY = 1;
/**
* 创建订单.
*
* <p> 创建订单需要传用户id和商品列表(商品id和商品数量).
*
* <p><pre>{@code
* 演示如何使用该方法
* List<Goods> items = new ArrayList<>();
* Goods goods = new Goods(1L, BigDecimal.ONE);
* Goods goods2 = new Goods(2L, BigDecimal.TEN);
* items.add(goods);
* items.add(goods2);
*
* Order order1 = new Order();
* order.setUserId("1");
* order.setItems(items);
* OrderService#createOrder(order);
* }
* </pre>
*
* @param order 订单信息
* @throws NullPointerException 参数信息为空
* @exception IllegalArgumentException 数量不合法
* @return 是否创建成功
* @version 1.0
* @see {@link Order}
*/
public boolean createOrder(Order order) throws IllegalArgumentException{
Objects.requireNonNull(order);
List<Goods> items = order.getItems();
items.forEach(goods -> {
BigDecimal quantity = goods.getQuantity();
if (quantity == null || BigDecimal.ZERO.compareTo(quantity) == 0) {
throw new IllegalArgumentException();
}
});
System.out.println("create order...");
return true;
}
}
原文链接:https://blog.csdn.net/vbirdbest/article/details/80296136