打开Window->Preferences->Java->Code Style->Code Templates

点击"Import",导入模板codetemplates.xml文件。

codetemplates.xml内容是我们自己预先定义好的,在这里先不详细描述,我们可以看到Eclipse Code Templates界面中间Configure generated code and comments区域包含了两个菜单树:Comment、Code,如下图所示:

Comments代表注释模板,Code代表代码模板,其中每一个子菜单代表子项的模板。

我们只要点击某一个子项,就会在界面下方的Pattern区域看到该项我们所定义的模板内容和格式,如下图所示:

如上图所示,当我们点击Comments下的Files子菜单时,下面的Pattern会显示Java文件的头部注释。

下面详细列出每一个子项的模板格式:

Comments-->Files(Java文件注释)

  1. /**
  2. * Project Name:${project_name}
  3. * File Name:${file_name}
  4. * Package Name:${package_name}
  5. * Date:${date}${time}
  6. * Copyright (c) ${year}, chenzhou1025@126.com All Rights Reserved.
  7. *
  8. */

Comments-->Types(Java类注释)

  1. /**
  2. * ClassName: ${type_name} <br/>
  3. * Function: ${todo} ADD FUNCTION. <br/>
  4. * Reason: ${todo} ADD REASON(可选). <br/>
  5. * date: ${date} ${time} <br/>
  6. *
  7. * @author ${user}
  8. * @version ${enclosing_type}${tags}
  9. * @since JDK 1.6
  10. */

Comments-->Fields(类字段注释)

  1. /**
  2. * ${field}:${todo}(用一句话描述这个变量表示什么).
  3. * @since JDK 1.6
  4. */

Comments-->Constructors(构造函数注释)

  1. /**
  2. * Creates a new instance of ${enclosing_type}.
  3. *
  4. * ${tags}
  5. */

Comments-->Methods(Java方法注释)

  1. /**
  2. * ${enclosing_method}:(这里用一句话描述这个方法的作用). <br/>
  3. * ${todo}(这里描述这个方法适用条件 – 可选).<br/>
  4. * ${todo}(这里描述这个方法的执行流程 – 可选).<br/>
  5. * ${todo}(这里描述这个方法的使用方法 – 可选).<br/>
  6. * ${todo}(这里描述这个方法的注意事项 – 可选).<br/>
  7. *
  8. * @author ${user}
  9. * ${tags}
  10. * @since JDK 1.6
  11. */

Comments-->Overriding methods(重写方法注释)

  1. /**
  2. * ${todo} 简单描述该方法的实现功能(可选).
  3. * ${see_to_overridden}
  4. */

Comments-->Delegate methods(代理方法注释)

  1. /**
  2. * ${tags}
  3. * ${see_to_target}
  4. */

Comments-->Getters(Java Getter方法注释)

  1. /**
  2. * ${bare_field_name}.
  3. *
  4. * @return  the ${bare_field_name}
  5. * @since   JDK 1.6
  6. */

Comments-->Setters(Java Setters方法注释)

  1. /**
  2. * ${param}.
  3. *
  4. * @param   ${param}    the ${bare_field_name} to set
  5. * @since   JDK 1.6
  6. */

Code-->New Java files(新建java文件代码模板)

  1. /**
  2. * Project Name:${project_name}
  3. * File Name:${file_name}
  4. * Package Name:${package_name}
  5. * Date:${date}${time}
  6. * Copyright (c) ${year}, chenzhou1025@126.com All Rights Reserved.
  7. *
  8. */
  9. ${filecomment}
  10. ${package_declaration}
  11. /**
  12. * ClassName:${type_name} <br/>
  13. * Function: ${todo} ADD FUNCTION. <br/>
  14. * Reason:   ${todo} ADD REASON. <br/>
  15. * Date:     ${date} ${time} <br/>
  16. * @author   ${user}
  17. * @version
  18. * @since    JDK 1.6
  19. * @see
  20. */
  21. ${typecomment}
  22. ${type_declaration}

Code-->Method body(方法体模板)

  1. // ${todo} Auto-generated method stub
  2. ${body_statement}

Code-->Constructor body(构造函数模板)

  1. ${body_statement}
  2. // ${todo} Auto-generated constructor stub

Code-->Getter body(字段Getter方法模板)

  1. return ${field};

Code-->Setter body(字段Setter方法模板)

  1. ${field} = ${param};

Code-->Catch block body(异常catch代码块模板)

  1. // ${todo} Auto-generated catch block
  2. ${exception_var}.printStackTrace();

其中codetemplates.xml内容如下:

  

eclipse--windows-preference--java--Code style--code Templater   处导入

操作

1.复制以下xml代码保存到xml空文件中,保存后使用eclipse到code Templater 导入即可。

2.查看效果代码

<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/** ${tags}

* ${see_to_target}
*/
</template><template autoinsert="false" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/** @Title: ${enclosing_method} <BR>
* @Description: <BR>
* @return: ${field_type} <BR>
*/
</template><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/** <p>Title: ${enclosing_method}</p>
* <p>Description: </p>
* ${tags}
* ${see_to_overridden}
*/
</template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/** @Title: ${enclosing_method}
* @Description:
* @param: ${tags}
* @return: ${return_type}
* @throws
* @author ${user}
* @Date ${date} ${time}
*/
</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/** FileName: ${file_name}
* @Description:
* Company: 北京钻天猴科技有限公司
* @author: ${user}
* @version V2.0
* Createdate: ${date} ${time}
*/
</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/** @package: ${package_name}
* @Title: ${type_name}
* @Description:
* @Company: 北京钻天猴科技有限公司
* @author ${user}
* @date ${date} ${time}
*/</template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
* @Fields ${field} :
*/</template><template autoinsert="false" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/** @Title: ${enclosing_type}
* @Description:
* @param: ${tags}
* @throws
*/
</template><template autoinsert="false" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/** @Title: ${enclosing_method} <BR>
* @Description: <BR>
* @return: ${field_type} <BR>
*/
</template></templates>

效果代码:

 

/**

* @package: cn.zuantianhou.manage.web.controller
      1. * @Title: PageController
      2. * @Description: 页面跳转控制类
      3. * @Company: 北京钻天猴科技有限公司
      4. * @author MrLu
      5. * @date 2017年2月16日 上午10:41:24
      6. */
      7. @Controller
      8. @RequestMapping("page")
      9. public class PageController {
      10. /**
      11. * @Title: toPage
      12. * @Description: 一级页面跳转
      13. * @param: @param pageName
      14. * @param: @param request
      15. * @param: @return
      16. * @return: String
      17. * @throws
      18. * @author MrLu
      19. * @Date 2017年2月16日 上午10:41:37
      20. */
      21. @RequestMapping(value="{pageName}",method=RequestMethod.GET)
      22. public String toPage(@PathVariable("pageName") String pageName,HttpServletRequest request){
      23. if(pageName.equals("reCaptcha")){
      24. return "reCaptcha";
      25. }
      26. Manager user = (Manager)request.getSession().getAttribute("user");
      27. if(user!=null){
      28. return pageName;
      29. }else{
      30. return "login";
      31. }
      32. }
      33. }

设置Code Templates的目的主要是为了统一各种注释的格式以及代码的模板,只要设定好Code Templates之后利用Eclipse就可以方便地生成我们自定义的注释,开发人员也容易接受!

Eclipse注释模版的更多相关文章

  1. eclipse code templates 设置(eclipse注释模版配置)

    文件(Files)注释标签:/** * @Title: ${file_name} * @Package ${package_name} * @Description: ${todo} * Copyri ...

  2. IDE-Ecplise-代码注释 模版 编码规范 配色

    说明: 代码注释主要用于方便代码后期维护,编码规范,增加代码阅读性和维护性.因网上看到的很多博客中片段局多,故整理后重写一篇,方便交流学习. 先看下加过注释模版后的效果. 如上图所示,创建类,方法和继 ...

  3. 【转载】 Eclipse注释模板设置详解

     Eclipse注释模板设置详解 网站推荐: 金丝燕网(主要内容是 Java 相关) 木秀林网(主要内容是消息队列)

  4. Eclipse设置类,方法注释模版

    首先打开Eclipse配置选项:Window->Preference->Java->Code Style->Code Template 配置Comments下的每个选项的模版, ...

  5. eclipse代码注释模版

    设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元 ...

  6. 【记录】eclipse / STS 设置注释模版格式/导入注释模版格式

    设置注释模板的入口:Window->Preference->Java->Code Style->Code Template 将如下保存在新创建的xml文件中,导入进去 < ...

  7. Eclipse ADT 代码注释模版

    具体怎么用: 将下面的内容拷贝出来保存为XML文件,进入,Eclipse :Window --> Java --> Code Style --> Code Templates-> ...

  8. Eclipse注释模板设置详解

    设置注释模板的入口:Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元素 ...

  9. eclipse注释快捷键(含方法注释)

    整段注释: /*public boolean executeUpdate(String sql) { System.out.println(sql); boolean mark=false; try ...

随机推荐

  1. Tensorflow细节-P54-变量

    1.首先复习前面所学知识: (1)g = tf.Graph() (2)别忘了初始化时的initializer (3)with tf.name_scope("generate_constant ...

  2. 任晓蕊 2019-2020-1 20199302《Linux内核原理与分析》第四周作业

    实验内容 在实验楼的环境中敲入命令 cd LinuxKernel/ qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img ...

  3. 【mssql】增删改查笔记

    一.插入数据 1.插入数据返回当前主键ID 当我们插入一条数据的时候,我们很多时候都想立刻获取当前插入的主键值返回以做它用.我们通常的做法有如下几种: 1. 先 select max(id) +1 , ...

  4. C# 异常 抛异常的时候 同时抛出 传入的参数

    abp的审计日志都把这些功能实现了 可以借鉴 抛异常的时候 同时抛出 传入的参数 大致这样实现,aop,方法执行先,先把参数写入到栈中,抛异常时,栈中自然就有此时的参数了. 可用于重现该异常. 获取把 ...

  5. 洛谷P1514引水入城

    题目 搜索加贪心其实并不需要用到\(DP\),搜索也是比较简单地搜索. 对于每个第一行的城市进行类似于滑雪那道题的搜索,然后记录最后一行它所覆盖的区间,易得一个一行城市只会有一个区间.然后可以在最后进 ...

  6. 【一起来烧脑】一步Sass学会体系

    [外链图片转存失败(img-G32u6UQ8-1563572536495)(https://upload-images.jianshu.io/upload_images/11158618-a03a58 ...

  7. Python逆向(一)—— 前言及Python运行原理

    一.前言 最近在学习Python逆向相关,涉及到python字节码的阅读,编译及反汇编一些问题.经过长时间的学习有了一些眉目,为了方便大家交流,特地将学习过程整理,形成了这篇专题.专题对python逆 ...

  8. sys 模块常用方法

    sys.argv 命令行参数List,第一个元素是程序本身路径 sys.modules.keys() 返回所有已经导入的模块列表 sys.exc_info() 获取当前正在处理的异常类,exc_typ ...

  9. Codeforces 1264C/1265E Beautiful Mirrors with queries (概率期望、DP)

    题目链接 http://codeforces.com/contest/1264/problem/C 题解 吐槽:为什么我赛后看cf的题就经常1h内做出Div.1 C, 一打cf就动不动AB题不会啊-- ...

  10. 【随记】安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se

    在安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se.. ...