-
IntelliJ에서 LiveTemplate을 이용하여 Code 조각들 손쉽게 typing 하기DevTools 2022. 4. 26. 07:49
개인적으로 사용하고 있는 LiveTemplate들을 지속적으로 업데이트할 예정입니다
예전에 File을 생성할 때에 주석을 남기는 법에 대해서 posting을 한 적이 있습니다.(아래 주소를 참고해 주세요)
그런데, FIie 생성 시에 특정 주석을 생성하는 게 아니라 평소에 다른 라이브러리들을 사용하는 것처럼, 어떠한 글자를 치면 관련된 메소드나 기능들이 자동완성되어서 SelectBox처럼 나열되게끔 지정하고 싶으신 수요가 분명히 있으실 겁니다.
자동완성을 위해서 약어를 지정하여 약어를 입력할 시에 원하는 코드들이 나오게끔 지정하는 기능이 Live Teplates 기능입니다.
1. 좌측 상단의 FIle 탭 클릭
2.Settings 클릭
3.Menu 검색창에서 Live Templates 검색
4. 기존의 여러 Templates 조각들을 무시하고 우측의 +버튼을 누릅니다
(만약 기존에 만들어 두신 template가 있다면 해당 template 이름을 클릭합니다. 저는 user라는 이름으로 자동 생성되었네요)
5. 그러면 1) Live Template을 선택할 것인지, 2) Template Group을 선택할 것인지 SelectBox가 나옵니다.
6. 그곳에 약어(abbreviation), 설명(Description), 사용하고자 하는 텍스트(Template text)를 입력합니다.
7. 그러면 좌측 하단에 빨간색 경고 말이 뜹니다.
No applicable contexts yet . Define
8. 이곳에서 Define을 눌러야 합니다. Define을 누르면 어떠한 확장자에서 이 Template Text를 사용하고 싶은지 물어봅니다.
9. 확장자를 지정하고, 원하는 Template Text를 입력합니다
10. 지정한 확장자의 파일로 가서, 약어를 입력합니다.
11. 가장 중요한 부분입니다. 지정해놓으신 live Template에 우클릭을 한 후, change context -> Java를 체크박스 체크 해줍니다.
혹시 도움이 될까 하여 공식 홈페이지 주소 링크 걸어두겠습니다.
https://blog.jetbrains.com/ko/2020/05/18/write-code-faster-using-live-templates-ko/
[개인적으로 사용하고 있는 Live Template 목록]
1.
Abbreviation:
@SpringSwaggerApiAnnotation
Description:
This template is made for swagger annotation
Template text:
@NotNull @ApiModelProperty( example = "", value = "", required = true )
2.
Abbreviation:
@SpringDTOAnnotations
Description:
This template is made for spring dto automatioon
Template text:
@Data @Builder @AllArgsConstructor @NoArgsConstructor @Accessors(chain = true) @EqualsAndHashCode(callSuper = false)
3.
Abbreviation:
<mapper<select<if
Description:
This template is made for mybatis xml
Template text:
<mapper namespace=""> <select id="" parameterType="" resultType=""> SELECT * FROM WHERE <if test=""></if> </select> </mapper>
4.
Abbreviation:
<mapper<select
Description:
This template is made for mybatis xml
Template text:
<mapper namespace=""> <select id="" parameterType="" resultType=""> SELECT * FROM WHERE </select> </mapper>
5.
Abbreviation:
<mapper<select
Description:
This template is made for mybatis xml
Template text:
<mapper namespace=""> <select id="" parameterType="" resultType=""> SELECT * FROM WHERE </select> </mapper>
6.
Abbreviation:
<mapper
Description:
This template is made for mybatis xml
Template text:
<mapper namespace=""> </mapper>
7.
Abbreviation:
<choose<when<otherwise
Description:
This template is made for mybatis xml
Template text:
<select id="" parameterType="" resultType=""> <choose> <when test=""> ${} </when> <when test=""> ${} </when> <otherwise> </otherwise> </choose> </select>
'DevTools' 카테고리의 다른 글