zoukankan      html  css  js  c++  java
  • 《跟我学IDEA》四、配置模板(提高代码编写效率)

    上一篇博文,我们学习了idea的一些实用配置,相信大家也对idea这个开发工具有了一个大概的了解。今天我们来学习模板的配置,idea提供很多模板从而提高编写代码的效率,比如说一些经常用的代码及生成文件时的模板。

    第一节:实时代码模板
    顾名思义,实时代码模板是指在编写程序中输入一段固定的字母可以快速生成自己想要的代码,例如:sout然后按Tab键会自动生成System.out.println();等等很多包括java、jsp、xml、css等。idea内置了很多模板这里都不在介绍了,idea还支持自定义模板,模板分组等,都在live templates下,自定义模板出来可以快速生成自己想要的代码外还可以比如定义方法注释模板文件注释模板等。
    新建动态模板分组

     

    定义自己的模板及模板说明还有需要模板输出的代码样式,参数用$$拼写。

    选择动态模板的适用范围

    编辑代码中的参数,后面选中表示鼠标不停留,idea自带了很多内置函数,可以参考官网介绍:
    https://www.jetbrains.com/help/idea/2017.1/creating-and-editing-template-variables.html

    设定方法注释的模板,这个没有固定格式,可根据自己公司规定。

    这里需要提一下,默认date和time函数式没有格式化的,但是输出的格式并不友好,所以这里可以根据自己喜好输出时间格式(对于强迫症患者很受用)

    IntelliJ IDEA 的实时代码模板保存在/templates 目录下,在输入sys 后按Tab 键,即立即生成预设语句。如果按Ctrl + J 则会先提示与之匹配的实时代码模板介绍,然后还需按Enter 才可完成预设语句的生成。

    第二节:文件模板
    这个下面可以定义很多文件类型的模板,我们就以class为例

    idea的内置变量,这里就不多介绍了。
    ${PACKAGE_NAME} - the name of the target package where the new class or interface will be created.
    ${PROJECT_NAME} - the name of the current project.
    ${FILE_NAME} - the name of the PHP file that will be created.
    ${NAME} - the name of the new file which you specify in the New File dialog box during the file creation.
    ${USER} - the login name of the current user.
    ${DATE} - the current system date.
    ${TIME} - the current system time.
    ${YEAR} - the current year.
    ${MONTH} - the current month.
    ${DAY} - the current day of the month.
    ${HOUR} - the current hour.
    ${MINUTE} - the current minute.
    ${PRODUCT_NAME} - the name of the IDE in which the file will be created.
    ${MONTH_NAME_SHORT} - the first 3 letters of the month name. Example: Jan, Feb, etc.
    ${MONTH_NAME_FULL} - full name of a month. Example: January, February, etc.

    第三节:Postfix Completion
    Postfix Completion 功能本质上也是代码模板,只是它比 Live Templates 来得更加便捷一点点而已。也很通俗易懂,这里就不多做介绍了。

    在学习时,参考了另一篇特别好的博客,以下有些内容也借鉴而来,忠心感谢fengzb,是你们无私的奉献,才让我们有了学习的参考,以下是地址:

    http://www.cnblogs.com/fengzb/p/idea04.html

  • 相关阅读:
    Es module vs require
    phaser3 画虚线实现
    新的计划
    [转]Boostrap Table的refresh和refreshOptions区别
    Storing Java objects in MySQL blobs
    【转】Ubuntu下搜狗输入法突然无法输入中文
    团队作业六
    团队作业七
    团队作业四
    团队作业三
  • 原文地址:https://www.cnblogs.com/xinhudong/p/8117715.html
Copyright © 2011-2022 走看看