- 12시에 일어나서 면접 과제를 풀었다( C#을 응용한 간단한 DB연동 후 CRUD)
- 주민등록증 재발급 수령하기
- 운동하기
- 스프링부트 공부 (✅)
- Application 생성(
@SpringBootApplication
)- HelloController, HelloControllerTest 클래스 생성, 어노테이션 파악 및 실습
- 진도 계속 나아가기
@SpringBootApplication
:
SpringApplication.run ? :
@RestController
:
@ResponseBody
를 각 메서드마다 선언한 것을 한번에 사용하는 의미.@GetMapping
:
RequestMapping(value="/hello" method = RequestMethod.GET)
으로 사용됐었음.@RunWith(SpringRunner.class)
:
@WebMvcTest(controllers = HelloController.class)
:
@Controller
, @ControllerAdvice
등 사용 가능. 단, @Service
, @Repository
, @Component
는 X.@Autowired
:
MockMvc
:
mvc.perform(get("/hello"))
:
.andExpect(status().isOk())
:
.andExpect(content().string(hello))
:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
깔끔하게 hello 출력완료!
Getter
Setter
생성자
toString
을 어노테이션으로 자동 생성해준다.
- build.gradle
compile('org.projectlombok:lombok')
작성- plugins -> marketplace(롬복 설치)
- Build/Compiler/Annotation Processors -> Enable annotation processing 체크
// MAIN
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public class HelloResponseDto {
private final String name;
private final int amount;
}
@Getter
:
@RequiredArgsConstructor
:
//TEST
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class HelloResponseDtoTest {
@Test
public void 롬복_기능_테스트(){
// given
String name = "test";
int amount = 1000;
// when
HelloResponseDto dto = new HelloResponseDto(name, amount);
// then
assertThat(dto.getName()).isEqualTo(name);
assertThat(dto.getAmount()).isEqualTo(amount);
}
}
@assertThat
:
isEqualTo
:
오늘도 목포량 만큼 열심히 공부했다. 내일부터는
JPA- 자바 표준ORM
을 공부할 것이다.