工欲善其事必先利其器
IDEA版本 2020.1.1
代码模板:Live Templates 和 Postfix Completion
1. 两种类型代码模板在设置中的路径:
- Live Templates:File | Settings | Editor | Live Templates
- Postfix Completion:File | Settings | Editor | General | Postfix Completion
2. 区别:
- Live Templates:可新增、删除、修改等调整;能直接通过缩写生成代码。
- Postfix Completion:不可调整;只能在代码前缀满足要求,才能通过缩写的后缀生成代码。
3. 使用 eg:
Live Templates :
psvm: main方法(public static void main(String[] args))
sout: 输出语句(System.out.println())
soutv: 输出语句(输出变量)
soutm: 输出语句(输出方法名)
fori:for循环语句
Postfix Completion:
.fori:new Integer(1).fori
.new:User.new ---> new User()
.lambda:testMethod.lambda ---> () -> testMethod()
idea 常用代码模板
/**
* 下列缩写是指java代码中的
* 【】中括号内的为代码缩写
*/
1. main 方法:
1. 【main】:public static void main(String[] args)
2. 【psvm】:public static void main(String[] args)
2. 输出语句:
1.【sout】:输出语句(System.out.println())
2.【souf】:输出语句(System.out.printf())
3.【soutv】:输出语句(输出变量)
4.【soutm】:输出语句(输出方法名)
5.【.sout】:输出语句(eg:args.sout ----> System.out.println(args);)
3. 循环语句:
a.for循环
1.【fori】:正向for循环
2.【.fori】:正向for循环
3.【.forr】: 逆向for循环
b.增强for循环:
1.【itar】
2.【.for】
3.【.iter】
4. if条件语句:
1.【ifn】:判断是否为null
2.【.null】:判断是否为null
3.【inn】:判断是否不为null
4.【.nn】:判断是否不为null
5.【.notnull】:判断是否不为null
5. 属性修饰符:
1.【prsf】:private static final
2.【psf】:public static final
3.【psfs】:public static final String
6. 注释:
1.【/**回车】
注: 更多代码模板的缩写,请在通过路径在设置中查看。