09 Eclipse设置代码注释模版

09 Eclipse设置代码注释模版

背景

在团队协作开发的项目中,为了降低沟通和维护成本,项目组成员使用统一的编码规范和注释规范显得尤为重要。本文就说一说如果在Eclipse中设置代码注释模版,技术经理可以要求所有的开发人员设置为统一的代码注释模版。

博客正文

1、 打开Eclipse,进入菜单Window->Preferences,打开首选项对话框如图:
在这里插入图片描述
2、在左侧树节点中找到Java->Code Style->Code Templates,在右侧选中Comments->Types,点击Edit按钮在弹出的Edit Template对话框中的Pattern区域设置类文档注释的模版,如下:
在这里插入图片描述

/**
 * 功能说明:
 * 修改说明:
 * @author ${user}
 * @date ${date} ${time}
 * @version 0.1
 */

3、 然后选择Comments->Methods,点击Edit按钮在弹出的Edit Template对话框中的Pattern区域设置方法文档注释的模版,结果如下:
在这里插入图片描述

/**
 * 功能说明:
 * 修改说明:
 * @author ${user}
 * @date ${date} ${time}
 * ${tags}
 */

4、 设置完毕后,新建工程,新建接口或类,使用文档注释,则结构会按注释模版自动建立,代码示例如下:

package com.wongoing.base;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;


/**
 * 功能说明 :数据访问基础接口
 * 修改说明
 * @author zhenglibing
 * @date 2017-03-22 上午11:47:54
 * @version V1.0
 */
public interface BaseDao<T, Serializable> {
	/**
	 * 功能说明:按主键查询-单值主键
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:43:05
	 * @param id 主键值
	 * @return	返回对应的实体对象
	 */
	public T getByPrimaryKey(Serializable id);
	/**
	 * 功能说明:按主键查询-组合主键
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:44:41
	 * @param param 组合主键参数,可以是实体对象,可以是map
	 * @return 返回对应的实体对象
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
	public T getByPrimaryKeys(Object param) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
	/**
	 * 功能说明:参数查询
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:46:06
	 * @param param 查询参数,可以是实体对象,可以是map
	 * @return 返回符合条件的实体集合
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
	public List<T> getByParam(Object param) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
	/**
	 * 功能说明:按Mapper文件中的语句ID和参数查询
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:47:05
	 * @param statementId Mapper文件中的语句ID
	 * @param param 查询参数
	 * @return 返回符合条件的实体集合
	 */
	public List<T> getByStatementParam(String statementId, Map<String, Object> param);
	/**
	 * 功能说明:按参数分页查询
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:49:02
	 * @param pageResult 带查询参数的分页对象,需在pageResult中传入pageIndex、pageSize、param
	 * @return 返回带结果数据的分页实体对象,在pageResult中返回totalSize、pageCount、data
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
	public PageResult<T> getPageByParam(PageResult<T> pageResult) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
	/**
	 * 功能说明:条件查询
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:52:51
	 * @param whereParam 查询条件,需要在map中增加key为where的键值对作为查询条件字符串(不带where关键词)
	 * @return 返回符合条件的实体集合
	 */
	public List<T> getByWhere(Map<String, Object> whereParam);
	/**
	 * 功能说明:按条件分页查询
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 上午11:54:44
	 * @param pageResult 带查询条件的分页对象,需在pageResult中传入pageIndex、pageSize、where
	 * @return 返回带结果数据的分页实体对象,在pageResult中返回totalSize、pageCount、data
	 */
	public PageResult<T> getPageByWhere(PageResult<T> pageResult);
	/**
	 * 功能说明:查询记录数
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:15:48
	 * @return 返回表中记录总数
	 */
	public int count();
	/**
	 * 功能说明:按参数查询记录数
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:19:47
	 * @param param 参数,可以是实体对象,可以是map
	 * @return 返回符合参数值的记录数
	 */
	public int countByParam(Map<String, Object> param);
	/**
	 * 功能说明:按条件查询记录数
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:22:00
	 * @param where 条件,条件字符串中不包括where关键词
	 * @return
	 */
	public int countByWhere(String where);
	/**
	 * 功能说明:追加记录
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:25:31
	 * @param entity 实体对象
	 * @return 返回追加的记录数
	 */
	public int insert(T entity);
	/**
	 * 功能说明:批量追加记录
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:26:39
	 * @param list 实体对象集合
	 * @return 返回追加的记录数
	 */
	public int insertBatch(List<T> list);
	/**
	 * 功能说明:按主键更新
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:28:06
	 * @param entity 要更新的实体对象
	 * @return 返回更新的记录数
	 */
	public int updateByPrimaryKey(T entity);
	/**
	 * 功能说明:批量更新
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:29:36
	 * @param list 要更新的实体对象集合
	 * @return 返回更新的记录数
	 */
	public int updateBatch(List<T> list);
	/**
	 * 功能说明:按主键删除-单值主键
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:37:04
	 * @param id 主键值
	 * @return 返回删除的记录数
	 */
	public int deleteByPrimaryKey(Serializable id);
	/**
	 * 功能说明:按主键删除-组合主键
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:37:56
	 * @param param 组合主键值,可以是实体对象,也可以是map
	 * @return 返回删除的记录数
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
	public int deleteByPrimaryKeys(Object param) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException;
	/**
	 * 功能说明:按参数删除记录
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:39:34
	 * @param param 参数
	 * @return 返回删除的记录数
	 */
	public int deleteByParam(Map<String, Object> param);
	/**
	 * 功能说明:批量删除
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:42:03
	 * @param ids 要删除的主键值集合
	 * @return 返回删除的记录数
	 */
	public int deleteBatch(List<Serializable> ids);
	/**
	 * 功能说明:按条件删除记录
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:43:08
	 * @param where 条件字符串(不包含where关键词)
	 * @return 返回删除的记录数
	 */
	public int deleteByWhere(String where);
	/**
	 * 功能说明:清空表中记录,即截断表(truncate)
	 * 修改说明:
	 * @author zhenglibing
	 * @date 2017-3-23 下午1:45:48
	 */
	public void clean();
}

猜你喜欢

转载自blog.csdn.net/zlbdmm/article/details/85065550
09
今日推荐