IDEA(2)—MAC代码模版

IDEA提供了许多的自带代码模版,这些模版主要是对于我们经常开发用到的代码制作成一个模版,比如for循环,这个是经常会用到的代码,如果没有代码模版,我们需要一个一个手动输入,有了代码模版也只需输入该模版的快捷键,就会自动生成for循环相关代码,提高开发效率。

一、自带代码模版

位置 Preferences —> Editor —> Live Templetes

java开发用地主要有4个组 iterationsotheroutputplain

1、iterations

这个组跟遍历相关,介绍下常用模版

1、iter   # for增强循环
2、itli   # list集合遍历 正序
3、itar   # 数组正序遍历
4、aitar  # 数组倒序遍历

示例

        List<String> str = new ArrayList();  
        //1、 iter 模版
        for (String s : str) {
        }
        //2、itli 模版
        for (int i = 0; i < str.size(); i++) {
            String s =  str.get(i);
        }
        //将集合转为数组
        String[] arr =(String[])str.toArray();
        //3、itar 数组正序输出
        for (int i = 0; i < arr.length; i++) {
            String s = arr[i];   
        }
        //4、ritar 数组倒叙输出
        for (int i = arr.length - 1; i >= 0; i--) {
            String s = arr[i];   
        }

2、other

常用模版

1、ifn   #判断当前对象是否等于null
2、inn   #判断当前对象是否不等于null
3、lazy  #判断当前对象是否等于null,如果等于null新建一个对象(lazy懒加载的意思)
4、toar  #集合转数组
5、psvm  #main方法 这个不能在某个方法内使用,要在方法外

示例

        String str = null;
        //1、ifn 模版
        if (str == null) {
        }
        //2、inn 模版
        if (str != null) {
        }
        //3、lazy 模版
        if (str == null) {
            str = new String();
        }
        List<String> stringList = new ArrayList();
        //4、toar 模版
        stringList.toArray(new Object[stringList.size()]);
        //5 psvm 模版
    public static void main(String[] args) {
    }

3、output

输出相关模版,常见模版

1、serr   #错误输出
2、sout   #输出
3、souf   #输出空字符串
4、soutv  #输出当前对象
5、soutp  #System.out.println("方法形参名 = " + 形参名);

示例

   //1、serr 错误输出
   System.err.println();
   //2、sout 正常输出
   System.out.println();
   //3、soutf 输出空字符串
   System.out.printf("");
   //4、soutv 输出当前对象
   String st = "小小";
   System.out.println("st = " + st);

4、plain

常见模版

1、prsf  # private static final 
2、psf   # public static final 
3、psfi  # public static final int 
4、psfs  # public static final String 
5、thr   # throw new 

二、自定义模版

上面的是一些IDEA自带的模版,但实际开发过程中,需要定制自己的代码模版,所以这里开始定制自己的代码模版。

1、创建组

自定义模版最好先创建一个分组,把自己自定义的模版都放到这个组中。

Editor->Live Templates,点击 + 号,新增一个属于自己的模板组。

这样组就创建好了。

2、创建模版


第四步这里有个4应用范围,出现上面提示时,需要点击define进行设置,点击define之后,选择java,表示该模板用于java文件,之后点击ok。

输入test 模版已经出来说明成功了。



``` 只要自己变优秀了,其他的事情才会跟着好起来(少将17) ```

原文地址:https://www.cnblogs.com/shoshana-kong/p/15015188.html