1.在哪里里设置注解模板
设置注释模板的位置
①.找到工作菜单
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190925210556393.png)
②.依次点进Window --> Preference --> Java->Code Style --> Code Template(或直接查找Code Template)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190925210619677.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)
③.点进Comments,按照下面所列的依次设定自动注释模板
![[外链图片转存失败(img-WcCLjx3P-1569416737270)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569410602741.png)]](https://img-blog.csdnimg.cn/20190925210630490.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)
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}
*/
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190925210649738.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)
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')}
*/
②Types 类
/**
* @ClassName: ${type_name}
* @Description: ${todo}
* @author Jeremy
* @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
*/
③Fields 字段
/**
* @Fields ${field} : ${todo}
* @author Jeremy
* @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
*/
④Constructors 构造函数
/**
* @Constructor: ${enclosing_type}
* @Description: ${enclosing_type}构造函数
* @author Jeremy
* @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
*/
⑤Methods 方法
/**
* @MethodName: ${enclosing_method}
* @Description: ${todo}
* @author Jeremy
* ${tags} ${return_type}
* @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
*/
⑥Overriding methods 重写方法
/**
* @MethodName: ${enclosing_method}
* @Description: ${todo}
* @author Jeremy
* ${tags}
* ${see_to_overridden}
* @date ${currentDate:date('yyyy-MM-dd hh:mm:ss')}
*/
5.如何使用注释及效果图
用快捷键Alt+Shift+J可以为文件头快速添加注释。
在需要添加注释的方法,类之前输入/** 然后回车,就会出现注释
②类名
![[外链图片转存失败(img-i095JxZw-1569416737274)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569416117629.png)]](https://img-blog.csdnimg.cn/20190925210723905.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)
④构造函数
![[外链图片转存失败(img-8qVUXhm9-1569416737275)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569416132743.png)]](https://img-blog.csdnimg.cn/20190925210732298.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)
⑤方法
![[外链图片转存失败(img-iA1YNSqA-1569416737277)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1569416046870.png)]](https://img-blog.csdnimg.cn/2019092521074211.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)
⑥Overriding methods 重写方法
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190925210805478.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0plcmVteV9fWXVhbg==,size_16,color_FFFFFF,t_70)