idea提供很多模板從而提高編寫代碼的效率絮姆,比如說一些經(jīng)常用的代碼及生成文件時的模板醉冤。
第一節(jié):實(shí)時代碼模板
顧名思義,實(shí)時代碼模板是指在編寫程序中輸入一段固定的字母可以快速生成自己想要的代碼篙悯,例如:sout然后按Tab鍵會自動生成System.out.println();等等很多包括java蚁阳、jsp、xml鸽照、css等螺捐。idea內(nèi)置了很多模板這里都不在介紹了,idea還支持自定義模板矮燎,模板分組等定血,都在live templates下,自定義模板出來可以快速生成自己想要的代碼外還可以比如定義方法注釋模板文件注釋模板等诞外。
新建動態(tài)模板分組
定義自己的模板及模板說明還有需要模板輸出的代碼樣式澜沟,參數(shù)用$$拼寫。
選擇動態(tài)模板的適用范圍
編輯代碼中的參數(shù)峡谊,后面選中表示鼠標(biāo)不停留茫虽,idea自帶了很多內(nèi)置函數(shù),可以參考官網(wǎng)介紹:https://www.jetbrains.com/help/idea/2017.1/creating-and-editing-template-variables.html
設(shè)定方法注釋的模板既们,這個沒有固定格式濒析,可根據(jù)自己公司規(guī)定。
這里需要提一下啥纸,默認(rèn)date和time函數(shù)式?jīng)]有格式化的号杏,但是輸出的格式并不友好,所以這里可以根據(jù)自己喜好輸出時間格式(對于強(qiáng)迫癥患者很受用)
IntelliJ IDEA 的實(shí)時代碼模板保存在/templates 目錄下斯棒,在輸入sys 后按Tab 鍵馒索,即立即生成預(yù)設(shè)語句。如果按Ctrl + J 則會先提示與之匹配的實(shí)時代碼模板介紹名船,然后還需按Enter 才可完成預(yù)設(shè)語句的生成绰上。
第二節(jié):文件模板
這個下面可以定義很多文件類型的模板,我們就以class為例
idea的內(nèi)置變量渠驼,這里就不多介紹了蜈块。
${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.
第三節(jié):Postfix Completion
Postfix Completion 功能本質(zhì)上也是代碼模板,只是它比 Live Templates 來得更加便捷一點(diǎn)點(diǎn)而已。也很通俗易懂百揭,這里就不多做介紹了爽哎。