Eclipse 注释模板的说明及设置(超详细)

1.在哪里里设置注解模板
设置注释模板的位置
①.找到工作菜单

在这里插入图片描述
②.依次点进Window --> Preference --> Java->Code Style --> Code Template(或直接查找Code Template)

在这里插入图片描述
③.点进Comments,按照下面所列的依次设定自动注释模板

[外链图片转存失败(img-WcCLjx3P-1569416737270)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569410602741.png)]
2.需要注释的元素说明
类型    说明
Files    文件
Types    类,接口
Fields    字段
constructors    构造函数
Methods    方法
Overriding methods    重写方法
Delegate methods    代理方法
Getter method    Bean中的get方法
Setter method    Bean中的set方法
3.注释模板的格式
点到需要设置的元素在点击edit(或者双击)
可以看到注释模板的格式都是以@xxx: 后面接一个EL表达式
EL表达式可以取出Eclipse对该元素注释的变量
点击下方的Insert Variable 可以查看该元素有哪些变量

/**  
 * @xxx: ${variable}
 * @xxx: ${variable}
 * @xxx: ${variable}
 * @xxx: ${variable}
 */

    1
    2
    3
    4
    5
    6

在这里插入图片描述
4.常用Variable
注意:不同元素所能使用的variable不同
Variable    格式    说明
date    $ {id:date [(format [,locale])]}    日期
file_name    ${file_name}    文件名
git_config    $ {名称:git_config(user.name)}
$ {电子邮件:git_config(user.email)}    从Git配置中检索一个值。
package_name    ${package_name}    包名
project_name    ${project_name}    项目名
type_name    ${type_name}    类名
return_type    ${return_type}    返回值类型
tags    {tags}    生成Javadoc标记(包括@ param,@ return )
enclosing_method    ${enclosing_method}    方法名
enclosing_type    ${enclosing_type}    类名
see_to_overridden    ${see_to_overridden}    重写的详细信息
5.我的注释模板
①Files 文件

/**  
 * @Title: ${file_name}
 * @Description: ${todo}
 * @author Jeremy
 * @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
 */

    1
    2
    3
    4
    5
    6

②Types 类

/**  
 * @ClassName: ${type_name}
 * @Description: ${todo}
 * @author Jeremy
 * @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
*/  

    1
    2
    3
    4
    5
    6
    7

③Fields 字段

/**  
 * @Fields ${field} : ${todo}
 * @author Jeremy
 * @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
 */  
 

    1
    2
    3
    4
    5
    6

④Constructors 构造函数

/**  
 * @Constructor: ${enclosing_type}
 * @Description: ${enclosing_type}构造函数
 * @author Jeremy
 * @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
 */

    1
    2
    3
    4
    5
    6

⑤Methods 方法

/**  
 * @MethodName: ${enclosing_method}
 * @Description: ${todo}
 * @author Jeremy
 * ${tags} ${return_type}
 * @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
 */  

    1
    2
    3
    4
    5
    6
    7

⑥Overriding methods 重写方法

/**  
 * @MethodName: ${enclosing_method}
 * @Description: ${todo}
 * @author Jeremy
 * ${tags}
 * ${see_to_overridden}
 * @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
 */  

    1
    2
    3
    4
    5
    6
    7
    8
    9

5.如何使用注释及效果图
用快捷键Alt+Shift+J可以为文件头快速添加注释。
在需要添加注释的方法,类之前输入/** 然后回车,就会出现注释
②类名

[外链图片转存失败(img-i095JxZw-1569416737274)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569416117629.png)]
④构造函数

[外链图片转存失败(img-8qVUXhm9-1569416737275)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569416132743.png)]
⑤方法

[外链图片转存失败(img-iA1YNSqA-1569416737277)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569416046870.png)]
⑥Overriding methods 重写方法

在这里插入图片描述
————————————————
版权声明:本文为CSDN博主「Jeremy__Yuan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Jeremy__Yuan/article/details/101386273

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值