模板代碼live template
教程
中文第三方博客:這個有點像是官網(wǎng)的翻譯版本讲坎,很實用儡嘶,主要是對函數(shù)的翻譯。
自己使用的一些感受
- 模板代碼無法實現(xiàn)像
.for
這樣的效果蜀变,只能sout
然后Tab
沟堡,或者選中代碼塊使用Ctrl + Alt + J
侧但,將選中代碼塊當(dāng)成參數(shù)傳入模板中(模板中定義的SELECTION
) - 要想實現(xiàn)
.for
這樣的效果,要使用另外一個方式:Postfix code completion - 目前
IDEA
只內(nèi)置了兩個函數(shù)SELECTION
和END
分享一些自己寫的
IFA
描述
mybatis
<if>
標簽
效果
<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>
標簽
效果
<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()
語句補全
效果
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>
最后
最后放一個 github 地址复亏,后面慢慢去維護模板