三、代码规范配置
3.1 文件头和作者信息
配置入口:依次打开 File -> Settings -> Editor -> File and Code Templates
。
Class
/*** Copyright (C) 2020-${YEAR}, Glodon Digital Supplier & Purchaser BU.* * All Rights Reserved.*/
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")/*** 类描述** @author 名字* @date ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}:${SECOND}*/
public class ${NAME}
{}
Interface
/*** Copyright (C) 2020-${YEAR}, Glodon Digital Supplier & Purchaser BU.* * All Rights Reserved.*/
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")/*** 类描述** @author 名字* @date ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}:${SECOND}*/
public interface ${NAME}
{}
Enum
/*** Copyright (C) 2020-${YEAR}, Glodon Digital Supplier & Purchaser BU.* * All Rights Reserved.*/
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")/*** 类描述** @author 名字* @date ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}:${SECOND}*/
public enum ${NAME}
{}
AnnotationType
/*** Copyright (C) 2020-${YEAR}, Glodon Digital Supplier & Purchaser BU.* * All Rights Reserved.*/
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")/*** 类描述** @author 名字* @date ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}:${SECOND}*/
public @interface ${NAME}
{}
3.2 统一缩进
咱们后台的Java项目统一要求:使用tab缩进。接来下我们来看一下怎么在IDEA中设置使用tab缩进。
设置入口: Settings -> Editor -> Code style -> Java
。
3.3 编码规范
要求 | 限制 |
---|---|
单个方法最大行数 | 不大于80行 |
单个方法最大列数 | 不大于120列 |
单个类最大行数 | 不大于1500行 |