在我们写程序中,注释是必不可少的,但是往往idea中默认的注释十分简单,没有
@description
、@author
、@time
等,如果自己每次都一个一个加真的是非常麻烦,所以我们需要加一些注释模板。
idea默认的注释
/**
*
*
*/
修改后的注释
类注释
/**
*
* @ClassName ${ClassName}
* @author ${author}
* date ${time}
*/
其中${} 里的内容是系统自动生成的
比如
/**
*
* @ClassName TopicController
* @author guojingting
* date 2020/11/17 20:53
*/
方法注释
/**
* @Description
* @Author ${author}
* @Date ${time}
* @Version 1.0
* @return ${parm}
* @Parm ${parm}
*/
比如:
/**
* @Description
* @Author guojingting
* @Date 2020/11/17 20:58
* @Version 1.0
* @return org.springframework.http.ResponseEntity<java.lang.Object>
* @Parm [topicDto]
**/
点击左上角的File->settings->Editor->Live Templates
在又上方有个添加的按钮,我们点击+号,然后点击Template Group
名字自己定,我这里是annotations
创建完就有了一个新的组
点击annotations,然后在点击+号,选择第一个Live Template
我写的是这样的,大家可以在增加一些,或者按自己需要的加
/**
* @Description $descripttion$
* @Author guojingting
* @Date $DATE$ $TIME$
* @Version 1.0
* @return $return$
* @Parm $parm$
**/
然后点击 ok,这样我们就配完了
我们点击apply,点击ok
我们在方法名的上面打/** 然后按enter
那么我们就有了想要的模板
比如
/**
* @Description
* @Author guojingting
* @Date 2020/11/17 20:58
* @Version 1.0
* @return org.springframework.http.ResponseEntity<java.lang.Object>
* @Parm [topicDto]
**/
public ResponseEntity<Object> addTopic(@ApiParam(name = "topicDto",value = "topic的Dto") @RequestBody TopicDto topicDto){
Map<String,Object> map = topicService.addTopic(topicDto);
if(map.containsKey("id")){
return new ResponseEntity<>(map,HttpStatus.OK);
}else {
return new ResponseEntity<Object>(map,HttpStatus.OK);
}
}
我们同样可以设置类注释,方法同设置方法注释道理一样
这里我设置的快捷键为/*
模板为
/**
* $TODO$
* @ClassName $className$
* @author guojingting
* date $date$ $time$
*/
这个大家也能根据自己的需要增加