java小白日记--环境配置篇

转载自:https://www.cnblogs.com/newpanderking/p/4887981.html

 

编码规范篇

1、使用eclipse的codeformatter格式化代码。

要下载插件:Eclipse Code Formatter插件

java小白日记--环境配置篇_第1张图片

然后进行配置如下图,codeformatter.xml文件是已经有的,导入使用即可,这里是公司的编码规范文件不方面提供O(∩_∩)O~:

java小白日记--环境配置篇_第2张图片

2、注释模板的配置,具体路径如下:Editor-->File and Code Templates -->Templates下对类,接口,枚举,和注解进行配置,这些是比较常用的需要模板配置,如下图:

java小白日记--环境配置篇_第3张图片

这里提供一些配置:

注释样板:

java小白日记--环境配置篇_第4张图片

复制代码

------类------

/**
 * Company
 * Copyright (C) 2004-${YEAR} All Rights Reserved.
 */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
/**
 *
 *
 * @author ${USER}
 * @version \$Id ${NAME}.java, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} ${USER} Exp $$
 */
public class ${NAME} {
}


------接口------

/**
 * Company
 * Copyright (C) 2004-${YEAR} All Rights Reserved.
 */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
/**
 *
 *
 * @author ${USER}
 * @version \$Id ${NAME}.java, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} ${USER} Exp $$
 */
public interface ${NAME} {
}

------枚举------

/**
 * Company
 * Copyright (C) 2004-${YEAR} All Rights Reserved.
 */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
/**
 *
 *
 * @author ${USER}
 * @version \$Id ${NAME}.java, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} ${USER} Exp $$
 */
public enum ${NAME} {
}

------注解------

/**
 * Company
 * Copyright (C) 2004-${YEAR} All Rights Reserved.
 */
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
/**
 *
 *
 * @author ${USER}
 * @version \$Id ${NAME}.java, v 0.1 ${YEAR}-${MONTH}-${DAY} ${TIME} ${USER} Exp $$
 */
public @interface ${NAME} {
}

复制代码

还有就是getter、setter生成配置注释模板,直接cmd+N调出这个页面

java小白日记--环境配置篇_第5张图片

java小白日记--环境配置篇_第6张图片

java小白日记--环境配置篇_第7张图片

修改需要的样式模板和注释即可,这里提供一个样式:

复制代码

-------getter----------

/**
* Getter method for property $field.name.
*
* @return property value of $field.name
*/

public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name =   $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field,   $project))))
#if ($field.boolean &&   $field.primitive)
    #if ($StringUtil.startsWithIgnoreCase($name, 'is'))
        #set($name = $StringUtil.decapitalize($name))
    #else
    is##
    #end
#else
get##
#end
${name}() {
return $field.name;
}


-------setter----------
/**
* Setter method for property $field.name.
*
* @param $field.name  value to be assigned to property $field.name
*/
#set($paramName =   $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
static ##
#end

void   set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field,   $project)))($field.type $paramName) {
#if ($field.name == $paramName)
    #if (!$field.modifierStatic)
    this.##
    #else
        $classname.##
    #end
#end
$field.name = $paramName;
}

复制代码

 

你可能感兴趣的:(知识点)