IDEA 模板代碼(live template)總結(jié)

模板代碼live template教程

官網(wǎng)文檔鏈接

中文第三方博客:這個(gè)有點(diǎn)像是官網(wǎng)的翻譯版本,很實(shí)用,主要是對(duì)函數(shù)的翻譯。

自己使用的一些感受

  1. 模板代碼無(wú)法實(shí)現(xiàn)像 .for 這樣的效果,只能 sout 然后 Tab,或者選中代碼塊使用 Ctrl + Alt + J,將選中代碼塊當(dāng)成參數(shù)傳入模板中(模板中定義的 SELECTION
  2. 要想實(shí)現(xiàn) .for 這樣的效果,要使用另外一個(gè)方式:Postfix code completion
  3. 目前 IDEA 只內(nèi)置了兩個(gè)函數(shù) SELECTIONEND

分享一些自己寫的

IFA

描述

mybatis <if> 標(biāo)簽

效果
<if test="judgeFullName != null ">
    AND judge_full_name = #{judgeFullName}
</if>
使用

輸入代碼 ,使用 Ctrl + Alt + J選中,選擇 IFA

模板
<if test="$SELECTION$ != null ">
   AND $VAR1$ $END$ = #{$SELECTION$}
</if>
<template name="IF" value="&lt;if test=&quot;$SELECTION$ != null &quot;&gt;&#10;   AND $VAR1$ $END$ = #{$SELECTION$}&#10;&lt;/if&gt;" description="if" toReformat="true" toShortenFQNames="true">
  <variable name="VAR1" expression="snakeCase(String)" defaultValue="$SELECTION$" alwaysStopAt="true" />
  <context>
    <option name="SQL" value="true" />
  </context>
</template>

FI

描述

mybatis <foreach> 標(biāo)簽

效果
<foreach item="item" collection="List" separator="," open="(" close=")" index="">
    #{item}
</foreach>
使用

輸入代碼,使用 Ctrl + Alt + J選中,選擇 FI

模板
<foreach item="item" collection="$SELECTION$" separator="," open="(" close=")" index="">
    #{item}
</foreach>
<template name="FI" value="&lt;foreach item=&quot;item&quot; collection=&quot;$SELECTION$&quot; separator=&quot;,&quot; open=&quot;(&quot; close=&quot;)&quot; index=&quot;&quot;&gt;&#10;    #{item}&#10;&lt;/foreach&gt;" description="for earch in" toReformat="true" toShortenFQNames="true">
  <context>
    <option name="SQL" value="true" />
  </context>
</template>

LikeC

描述

MYSQL LIKE CONCAT() 語(yǔ)句補(bǔ)全

效果
LIKE CONCAT('%',#{judge_full_name} ,'%' )
使用

輸入代碼,使用 Ctrl + Alt + J選中,選擇 LikeC

模板
LIKE CONCAT('%',#{$SELECTION$} ,'%' )
<template name="LikeC" value="LIKE CONCAT('%',#{$SELECTION$} ,'%' )" description="Like Concat" toReformat="true" toShortenFQNames="true">
  <context>
    <option name="SQL" value="true" />
  </context>
</template>

最后

最后放一個(gè) github 地址,后面慢慢去維護(hù)模板

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容