안니옹하세요? 정말 오랜만입니다.
그동안 무슨 일이 있었냐면 취업을 하고 좀 바빴습니다.
회사에서 스프링을 사용해서 그거 가지고 프로젝트를 꽤나 많이 만들었는데요.. (기초 직무 교육)
스프링을 하나도 모르던 제가 이제 눈감고(는 솔직히 거짓말이고) 프로젝트 생성하고 기초 설정을 능숙하게 할 줄 알게 되었고 controller, domain, mapper, repository, dao, dto, service ..등등의 개념들을 이해하게 될 정도로 프로젝트를 좀 많이 다뤘습니다.
처음에는 뭐... 저렇게 프로세스가 가는데 이해가 하나도 안됐지만 이제 어떻게 되는지 정도는 안다고 당당하게 말할 수 있음..
지금도 '잘' 한다고는 못하지만 그래도 어디가서 스프링부트좀 해봤습니다! 라고 말할 수 있을 정도지 않을까요..?
저는 다뤄본 언어는 여러가지지만 자신있게 할 수 있다고 말할 수 있는건 파이썬 밖에 없었는데요, 자바도 어느정도 초급~중급정도로 다룰 줄 알게 된 것 같습니다..
한달 반 동안의 시간이 이렇게 저를 바꿔놨습니다..
하여간 본론으로 넘어가죠 서론이 넘 길어ㅋㅋ
Window 11
IntelliJ Ultimate
openjdk 11
Spring Boot 2.7.10
(회사 컴이 윈도우라서 윈도우 환경에서 개발중)
인텔리제이 얼티밋을 사용하면 스프링이니셜라이저를 인텔리제이에서 이용할 수 있다. 얼티밋이 아닌 커뮤니티 버전을 사용한다면 Spring Initializer에서 스프링 프로젝트를 생성하고 인텔리제이에서 임포트해서 사용할 수 있다. (따로 만든 프로젝트를 임포트 하는 방법은 검색하면 잘 나옴)
Dependencies
에 필요한 것들을 검색해서 넣어준다.dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.0'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
제가 가장 최근에 만든 프로젝트의 dependencies 입니다. 참고만 하세염.
build.gradle
에서 확인하실 수 있다.
이후 create
를 누르면 알아서 빌드까지 완.
application.properties
보다는 application.yml
을 많이 사용하는 추세라고 한다. (거의 안쓴다는데요?)spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://[데이터베이스 주소]/[데이터베이스 이름]
username: 사용자이름
password: 사용자비밀번호
devtools:
livereload:
enabled: true
restart:
enabled: false
thymeleaf:
cache: false
enabled: true
prefix: classpath:/templates/html/
suffix: .html
mybatis:
mapper-locations: classpath:mapper/**/*.xml
configuration:
map-underscore-to-camel-case: true
.xml
파일들을 mapper로 읽겠다는 뜻이다.resources
안에 mapper
폴더를 만들어서 관리하는 편이다.이렇게 하면 기본 설정은 끝! 다음은 mapper를 작성하고 db의 데이터를 불러오는 방법을 확인해보도록 하장.