Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- Serialization
- 혼자 공부하는 C언어
- s
- 알기쉬운 알고리즘
- Graph
- 이것이 자바다
- Algorithm
- 윤성우의 열혈 자료구조
- 이스케이프 문자
- buffer
- Stack
- 메모리구조
- datastructure
- JSON
- R
- C 언어 코딩 도장
- coding test
- 윤성우 열혈자료구조
- insertion sort
- Selection Sorting
- list 컬렉션
- stream
- C programming
Archives
- Today
- Total
Engineering Note
[스프링 부트 입문 10] 롬복과 리팩토링 본문
본 내용은 홍팍 스프링 부트 강좌를 참고하였습니다.
https://www.youtube.com/watch?v=2VYBQ_99RJg&t=9s
Mission
- 롬복을 활용하여 기존 코드를 리팩토링 하자
롬복을 사용하기 위해서는 build.gradle에 아래 코드를 입력해준다.
dependencies {
//Lombok adding
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
그리고 인텔리제이 plugins에서 lombok을 설치해준다.
Lombok을 이용하면 Constructor(생성자), toString, getter, setter등의 자주 사용하는 메서드들을 어노테이션으로 작성할 수 있다.
아래코드는 ArticleForm과 toString을 리팩토링 한 코드이다. @AllArgsConstructor을 이용하면 생성자를, @ToString를 이용하면 toString을 대체해서 사용할 수 있다.
리팩토링 전
package com.example.boardproject.dto;
import com.example.boardproject.entity.Article;
public class ArticleForm {
private String title;
private String content;
public ArticleForm(String title, String content) {
this.title = title;
this.content = content;
}
@Override
public String toString() {
return "ArticleForm{" +
"title='" + title + '\'' +
", content='" + content + '\'' +
'}';
}
public Article toEntity() {
return new Article(null,title,content);
리팩토링 후
package com.example.boardproject.dto;
import com.example.boardproject.entity.Article;
import lombok.AllArgsConstructor;
import lombok.ToString;
@AllArgsConstructor
@ToString
public class ArticleForm {
private String title;
private String content;
public Article toEntity() {
return new Article(null,title,content);
'Server > Spring' 카테고리의 다른 글
[스프링 부트 입문] 12 데이터 목록 보기 (0) | 2022.07.12 |
---|---|
[스프링 부트 입문 11] 데이터 조회하기 (0) | 2022.07.10 |
[스프링 부트 입문 09]DB 테이블과 SQL (0) | 2022.07.08 |
[스프링부트 입문 08] 데이터 생성하기 with JPA (0) | 2022.07.08 |
[스프링 부트 입문 07] 폼 데이터 주고 받기 (0) | 2022.07.08 |
Comments