模板代碼live template教程
中文第三方博客:這個(gè)有點(diǎn)像是官網(wǎng)的翻譯版本,很實(shí)用,主要是對(duì)函數(shù)的翻譯。
自己使用的一些感受
- 模板代碼無(wú)法實(shí)現(xiàn)像
.for這樣的效果,只能sout然后Tab,或者選中代碼塊使用Ctrl + Alt + J,將選中代碼塊當(dāng)成參數(shù)傳入模板中(模板中定義的SELECTION) - 要想實(shí)現(xiàn)
.for這樣的效果,要使用另外一個(gè)方式:Postfix code completion - 目前
IDEA只內(nèi)置了兩個(gè)函數(shù)SELECTION和END
分享一些自己寫的
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="<if test="$SELECTION$ != null "> AND $VAR1$ $END$ = #{$SELECTION$} </if>" 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="<foreach item="item" collection="$SELECTION$" separator="," open="(" close=")" index=""> #{item} </foreach>" 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ù)模板