├── .gitignore ├── 01. 객체지향 └── 강의자료 │ └── 01. 객체지향이란.pdf ├── 02. 디자인패턴 ├── SourceCode │ └── design-pattern │ │ ├── .idea │ │ ├── .gitignore │ │ └── description.html │ │ ├── design-pattern.iml │ │ └── src │ │ └── com │ │ └── company │ │ └── design │ │ ├── Main.java │ │ ├── adapter │ │ ├── AirConditioner.java │ │ ├── Cleaner.java │ │ ├── Electronic110V.java │ │ ├── Electronic220V.java │ │ ├── HairDryer.java │ │ └── SocketAdapter.java │ │ ├── aop │ │ ├── AopProxy.java │ │ └── IAopBrowser.java │ │ ├── decorator │ │ ├── A3.java │ │ ├── A4.java │ │ ├── A5.java │ │ ├── Audi.java │ │ ├── AudiModelDecorator.java │ │ └── ICar.java │ │ ├── facade │ │ ├── FileReader.java │ │ ├── FileWriter.java │ │ ├── FtpProtocol.java │ │ └── SftpClient.java │ │ ├── observer │ │ ├── IButtonClickListener.java │ │ └── MyButton.java │ │ ├── proxy │ │ ├── Browser.java │ │ ├── BrowserProxy.java │ │ ├── Html.java │ │ ├── IBroswer.java │ │ └── IBrowser.java │ │ ├── singleton │ │ ├── AClazz.java │ │ ├── BClazz.java │ │ └── SocketClient.java │ │ └── strategy │ │ ├── Base64Strategy.java │ │ ├── Encoder.java │ │ ├── EncodingStrategy.java │ │ └── NormalStrategy.java └── 강의자료 │ └── 02. 디자인패턴.pdf ├── 03. 웹 개발 개론 └── 강의자료 │ └── 03. 웹개발개론.pdf ├── 04. Spring Boot 시작하기 └── 강의자료 │ └── 04. Spring Boot 시작하기.pdf ├── 05. Spring 조금 더 들여다보기 ├── SourceCode │ ├── aop │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── aop │ │ │ │ │ ├── AopApplication.java │ │ │ │ │ ├── annotation │ │ │ │ │ ├── Decode.java │ │ │ │ │ └── Timer.java │ │ │ │ │ ├── aop │ │ │ │ │ ├── DecodeAop.java │ │ │ │ │ ├── ParameterAop.java │ │ │ │ │ └── TimerAop.java │ │ │ │ │ ├── controller │ │ │ │ │ └── RestApiController.java │ │ │ │ │ └── dto │ │ │ │ │ └── User.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── aop │ │ │ └── AopApplicationTests.java │ ├── ioc │ │ ├── .idea │ │ │ ├── .gitignore │ │ │ └── description.html │ │ ├── ioc.iml │ │ └── src │ │ │ └── com │ │ │ └── company │ │ │ └── ioc │ │ │ ├── Base64Encoder.java │ │ │ ├── Encoder.java │ │ │ ├── IEncoder.java │ │ │ ├── Main.java │ │ │ └── UrlEncoder.java │ ├── object-mapper │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ ├── Main.java │ │ │ └── dto │ │ │ ├── Car.java │ │ │ └── User.java │ └── spring-ioc │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── ioc │ │ │ │ ├── ApplicationContextProvider.java │ │ │ │ ├── Base64Encoder.java │ │ │ │ ├── Encoder.java │ │ │ │ ├── IEncoder.java │ │ │ │ ├── IocApplication.java │ │ │ │ └── UrlEncoder.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── ioc │ │ └── IocApplicationTests.java └── 강의자료 │ ├── 01. 스프링의 핵심 │ └── 01. 스프링의 핵심.pdf │ ├── 02. IoC-DI │ └── 02. IoC-DI.pdf │ ├── 03. AOP │ └── 03. AOP.pdf │ └── 07. 여러가지 Annotation │ └── 07. 여러가지 Annotation.pdf ├── 06. 스프링의 기능을 활용해보자 ├── SourceCode │ ├── async │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── async │ │ │ │ │ ├── AsyncApplication.java │ │ │ │ │ ├── config │ │ │ │ │ └── AppConfig.java │ │ │ │ │ ├── controller │ │ │ │ │ └── ApiController.java │ │ │ │ │ └── service │ │ │ │ │ └── TaskService.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── async │ │ │ └── AsyncApplicationTests.java │ ├── exception │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── exception │ │ │ │ │ ├── ExceptionApplication.java │ │ │ │ │ ├── advice │ │ │ │ │ └── ApiControllerAdvice.java │ │ │ │ │ ├── controller │ │ │ │ │ └── ApiController.java │ │ │ │ │ └── dto │ │ │ │ │ ├── Error.java │ │ │ │ │ ├── ErrorResponse.java │ │ │ │ │ └── User.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── exception │ │ │ └── ExceptionApplicationTests.java │ ├── filter-and-interceptor │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── filterandinterceptor │ │ │ │ │ ├── FilterandinterceptorApplication.java │ │ │ │ │ ├── annotation │ │ │ │ │ └── AuthUser.java │ │ │ │ │ ├── config │ │ │ │ │ └── MvcConfig.java │ │ │ │ │ ├── controller │ │ │ │ │ └── ApiController.java │ │ │ │ │ ├── dto │ │ │ │ │ └── User.java │ │ │ │ │ ├── filter │ │ │ │ │ └── RequestFilter.java │ │ │ │ │ └── interceptor │ │ │ │ │ └── AuthInterceptor.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── filterandinterceptor │ │ │ └── FilterandinterceptorApplicationTests.java │ ├── object_mapper │ │ ├── .idea │ │ │ ├── .gitignore │ │ │ └── modules │ │ │ │ └── object_mapper.iml │ │ ├── build.gradle │ │ ├── build │ │ │ └── tmp │ │ │ │ └── compileJava │ │ │ │ └── source-classes-mapping.txt │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── sample.json │ │ ├── settings.gradle │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ ├── Main.java │ │ │ └── dto │ │ │ ├── Car.java │ │ │ └── User.java │ └── validation │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── validation │ │ │ │ ├── ValidationApplication.java │ │ │ │ ├── annotation │ │ │ │ └── YearMonth.java │ │ │ │ ├── controller │ │ │ │ └── ApiController.java │ │ │ │ ├── dto │ │ │ │ ├── Car.java │ │ │ │ ├── Req.java │ │ │ │ └── User.java │ │ │ │ └── validator │ │ │ │ └── YearMonthValidator.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── validation │ │ └── ValidationApplicationTests.java └── 강의자료 │ ├── 01. Spring Boot Validation │ └── 01. Spring Boot Validation.pdf │ ├── 02. Spring Boot Custom Validation │ └── 02. Spring Boot Custom Validation.pdf │ ├── 03. Spring Boot Validation 모범사례 │ └── 03. Spring Boot Validation 모범사례.pdf │ ├── 04. Spring Boot Exception 처리 │ └── 04. Spring Boot Exception 처리.pdf │ ├── 05. Filter 와 Interceptor의 활용 │ └── 05. Filter 와 Interceptor의 활용.pdf │ └── 06. 비동기 처리 하기 │ └── 06. 비동기 처리 하기.pdf ├── 07. Server to Server 간의 연동 ├── sourceCode │ ├── rest-template │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── resttemplate │ │ │ │ │ ├── RestTemplateApplication.java │ │ │ │ │ ├── controller │ │ │ │ │ └── UserApiController.java │ │ │ │ │ ├── dto │ │ │ │ │ ├── Car.java │ │ │ │ │ └── User.java │ │ │ │ │ └── service │ │ │ │ │ └── UserService.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── resttemplate │ │ │ └── RestTemplateApplicationTests.java │ └── server │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── server │ │ │ │ ├── ServerApplication.java │ │ │ │ ├── controller │ │ │ │ └── UserApiController.java │ │ │ │ └── dto │ │ │ │ ├── Car.java │ │ │ │ └── User.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── server │ │ └── ServerApplicationTests.java └── 강의자료 │ └── 07. Server to Server 통신.pdf ├── 08. JUnit ├── sourceCode │ ├── calculator │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── calculator │ │ │ │ │ ├── CalculatorApplication.java │ │ │ │ │ ├── controller │ │ │ │ │ └── CalculatorApiController.java │ │ │ │ │ ├── dto │ │ │ │ │ ├── CalculatorReq.java │ │ │ │ │ └── CalculatorRes.java │ │ │ │ │ └── service │ │ │ │ │ ├── DollarCalculator.java │ │ │ │ │ ├── ICalculator.java │ │ │ │ │ └── MarketServer.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── calculator │ │ │ ├── AbstractCalculatorReqApplicationTests.java │ │ │ └── controller │ │ │ └── CalculatorApiControllerTest.java │ └── java-calculator │ │ ├── .idea │ │ └── .gitignore │ │ ├── build.gradle │ │ ├── build │ │ ├── reports │ │ │ └── tests │ │ │ │ └── test │ │ │ │ ├── classes │ │ │ │ └── Test.html │ │ │ │ ├── css │ │ │ │ ├── base-style.css │ │ │ │ └── style.css │ │ │ │ ├── index.html │ │ │ │ ├── js │ │ │ │ └── report.js │ │ │ │ └── packages │ │ │ │ └── default-package.html │ │ └── test-results │ │ │ └── test │ │ │ └── binary │ │ │ ├── output.bin │ │ │ ├── output.bin.idx │ │ │ └── results.bin │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle │ │ └── src │ │ ├── main │ │ └── java │ │ │ ├── Calculator.java │ │ │ ├── DollarCalculator.java │ │ │ ├── ICalculator.java │ │ │ └── MarketServer.java │ │ └── test │ │ └── java │ │ └── Test.java └── 강의자료 │ └── 08. Junit란.pdf ├── 09. swagger ├── gradlew ├── gradlew.bat ├── sourceCode │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── swagger │ │ │ │ ├── SwaggerApplication.java │ │ │ │ ├── controller │ │ │ │ └── ApiController.java │ │ │ │ └── dto │ │ │ │ ├── UserRequest.java │ │ │ │ └── UserResponse.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── swagger │ │ └── SwaggerApplicationTests.java └── 강의자료 │ └── 09. Swagger.pdf ├── 10. 네이버 지역검색 API를 활용한 맛집 List 만들기 └── restaurant │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── restaurant │ │ │ ├── RestaurantApplication.java │ │ │ ├── controller │ │ │ ├── ApiController.java │ │ │ └── PageController.java │ │ │ ├── db │ │ │ ├── MemoryDbEntity.java │ │ │ ├── MemoryDbRepositoryAbstract.java │ │ │ └── MemoryDbRepositoryIfs.java │ │ │ ├── naver │ │ │ ├── NaverClient.java │ │ │ └── dto │ │ │ │ ├── SearchImageReq.java │ │ │ │ ├── SearchImageRes.java │ │ │ │ ├── SearchLocalReq.java │ │ │ │ └── SearchLocalRes.java │ │ │ └── wishlist │ │ │ ├── dto │ │ │ └── WishListDto.java │ │ │ ├── entity │ │ │ └── WishListEntity.java │ │ │ ├── repository │ │ │ └── WishListRepository.java │ │ │ └── service │ │ │ └── WishListService.java │ └── resources │ │ ├── application.yaml │ │ ├── static │ │ └── js │ │ │ └── main.js │ │ └── templates │ │ └── aaaa │ │ └── main.html │ └── test │ ├── java │ └── com │ │ └── example │ │ └── restaurant │ │ ├── RestaurantApplicationTests.java │ │ ├── naver │ │ └── NaverClientTest.java │ │ └── wishlist │ │ ├── repository │ │ └── WishListRepositoryTest.java │ │ └── service │ │ └── WishListServiceTest.java │ └── resources │ └── application.yaml ├── LICENSE ├── README.md └── food-list.zip /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | 4 | # Ignore Gradle GUI config 5 | gradle-app.setting 6 | 7 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 8 | !gradle-wrapper.jar 9 | 10 | # Cache of project 11 | .gradletasknamecache 12 | 13 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 14 | # gradle/wrapper/gradle-wrapper.properties 15 | 16 | *.class 17 | *.xml 18 | -------------------------------------------------------------------------------- /01. 객체지향/강의자료/01. 객체지향이란.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/01. 객체지향/강의자료/01. 객체지향이란.pdf -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../:\git-hub\design-pattern\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/.idea/description.html: -------------------------------------------------------------------------------- 1 | Simple Java application that includes a class with main() method -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/design-pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/adapter/AirConditioner.java: -------------------------------------------------------------------------------- 1 | package com.company.design.adapter; 2 | 3 | public class AirConditioner implements Electronic220V{ 4 | @Override 5 | public void connect() { 6 | System.out.println("220v 에어컨 ON"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/adapter/Cleaner.java: -------------------------------------------------------------------------------- 1 | package com.company.design.adapter; 2 | 3 | public class Cleaner implements Electronic220V{ 4 | @Override 5 | public void connect() { 6 | System.out.println("220v 청소기 ON"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/adapter/Electronic110V.java: -------------------------------------------------------------------------------- 1 | package com.company.design.adapter; 2 | 3 | public interface Electronic110V { 4 | public void powerOn(); 5 | } 6 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/adapter/Electronic220V.java: -------------------------------------------------------------------------------- 1 | package com.company.design.adapter; 2 | 3 | public interface Electronic220V { 4 | public void connect(); 5 | } 6 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/adapter/HairDryer.java: -------------------------------------------------------------------------------- 1 | package com.company.design.adapter; 2 | 3 | public class HairDryer implements Electronic110V { 4 | @Override 5 | public void powerOn() { 6 | System.out.println("110v 헤어드라이기 ON"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/adapter/SocketAdapter.java: -------------------------------------------------------------------------------- 1 | package com.company.design.adapter; 2 | 3 | public class SocketAdapter implements Electronic110V { 4 | 5 | private Electronic220V electronic220V; 6 | 7 | public SocketAdapter(Electronic220V electronic220V){ 8 | this.electronic220V = electronic220V; 9 | } 10 | 11 | @Override 12 | public void powerOn() { 13 | electronic220V.connect(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/aop/AopProxy.java: -------------------------------------------------------------------------------- 1 | package com.company.design.aop; 2 | 3 | import com.company.design.proxy.Html; 4 | 5 | import java.util.function.Consumer; 6 | import java.util.function.Function; 7 | import java.util.function.Supplier; 8 | 9 | public class AopProxy implements IAopBrowser { 10 | 11 | private String url; 12 | private Html html; 13 | private Runnable before; 14 | private Runnable after; 15 | 16 | public AopProxy(String url){ 17 | this.url = url; 18 | } 19 | 20 | public AopProxy(String url, Runnable before, Runnable after) { 21 | this.url = url; 22 | this.before = before; 23 | this.after = after; 24 | } 25 | 26 | @Override 27 | public Html show() throws InterruptedException { 28 | after.run(); 29 | 30 | if(html == null){ 31 | this.html = new Html(url); 32 | System.out.println("BrowserProxy loading html from "+url); 33 | } 34 | System.out.println("BrowserProxy use cache html"); 35 | Thread.sleep(2000); 36 | before.run(); 37 | return html; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/aop/IAopBrowser.java: -------------------------------------------------------------------------------- 1 | package com.company.design.aop; 2 | 3 | import com.company.design.proxy.Html; 4 | 5 | public interface IAopBrowser { 6 | Html show() throws InterruptedException; 7 | } 8 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/decorator/A3.java: -------------------------------------------------------------------------------- 1 | package com.company.design.decorator; 2 | 3 | public class A3 extends AudiModelDecorator { 4 | 5 | public A3(ICar audi) { 6 | super(audi); 7 | this.modelPrice = 1000; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/decorator/A4.java: -------------------------------------------------------------------------------- 1 | package com.company.design.decorator; 2 | 3 | public class A4 extends AudiModelDecorator { 4 | public A4(ICar audi) { 5 | super(audi); 6 | this.modelPrice = 2000; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/decorator/A5.java: -------------------------------------------------------------------------------- 1 | package com.company.design.decorator; 2 | 3 | public class A5 extends AudiModelDecorator { 4 | 5 | public A5(ICar audi) { 6 | super(audi); 7 | this.modelPrice = 3000; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/decorator/Audi.java: -------------------------------------------------------------------------------- 1 | package com.company.design.decorator; 2 | 3 | public class Audi implements ICar{ 4 | 5 | private int cost; 6 | 7 | public Audi(int cost){ 8 | this.cost = cost; 9 | } 10 | 11 | @Override 12 | public int getPrice(){ 13 | return this.cost; 14 | } 15 | 16 | @Override 17 | public void showCost() { 18 | System.out.println("Audi Base는 "+cost+" 원 입니다."); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/decorator/AudiModelDecorator.java: -------------------------------------------------------------------------------- 1 | package com.company.design.decorator; 2 | 3 | public class AudiModelDecorator implements ICar{ 4 | 5 | protected ICar audi; 6 | protected int modelPrice; 7 | 8 | public AudiModelDecorator(ICar audi){ 9 | this.audi = audi; 10 | } 11 | 12 | @Override 13 | public int getPrice() { 14 | return audi.getPrice(); 15 | } 16 | 17 | @Override 18 | public void showCost() { 19 | System.out.println("가격은 "+(audi.getPrice()+modelPrice)+" 만원 입니다"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/decorator/ICar.java: -------------------------------------------------------------------------------- 1 | package com.company.design.decorator; 2 | 3 | public interface ICar { 4 | int getPrice(); 5 | void showCost(); 6 | } 7 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/facade/FileReader.java: -------------------------------------------------------------------------------- 1 | package com.company.design.facade; 2 | 3 | public class FileReader { 4 | 5 | public FileReader(String fileName){ 6 | 7 | } 8 | 9 | public void fileConnect(){ 10 | System.out.println("FileReader Connected"); 11 | } 12 | 13 | public String fileRead(){ 14 | return "content"; 15 | } 16 | 17 | public void fileDisconnect(){ 18 | System.out.println("FileReader disConnected"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/facade/FileWriter.java: -------------------------------------------------------------------------------- 1 | package com.company.design.facade; 2 | 3 | public class FileWriter { 4 | 5 | public FileWriter(String fileName){ 6 | 7 | } 8 | 9 | public void fileConnect(){ 10 | System.out.println("FileWriter Connected"); 11 | } 12 | 13 | public void fileWrite(String content){ 14 | System.out.println("write : "+content); 15 | } 16 | 17 | public void fileDisconnect(){ 18 | System.out.println("FileWriter disConnected"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/facade/FtpProtocol.java: -------------------------------------------------------------------------------- 1 | package com.company.design.facade; 2 | 3 | public class FtpProtocol { 4 | 5 | public FtpProtocol(String host, int port, String path){ 6 | System.out.println("ftp server create"); 7 | } 8 | 9 | 10 | public void connect(){ 11 | System.out.println("ftp server connected"); 12 | } 13 | 14 | public void moveDirectory(){ 15 | System.out.println("move path"); 16 | } 17 | 18 | public void disConnect(){ 19 | System.out.println("ftp server disConnected"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/facade/SftpClient.java: -------------------------------------------------------------------------------- 1 | package com.company.design.facade; 2 | 3 | public class SftpClient { 4 | 5 | private FtpProtocol ftpProtocol; 6 | private FileReader fileReader; 7 | private FileWriter fileWriter; 8 | 9 | public SftpClient(String host, int port, String path, String fileName){ 10 | this.ftpProtocol = new FtpProtocol(host, port, path); 11 | this.fileReader = new FileReader(fileName); 12 | this.fileWriter = new FileWriter(fileName); 13 | } 14 | 15 | public void connect(){ 16 | this.ftpProtocol.connect(); 17 | this.ftpProtocol.moveDirectory(); 18 | this.fileReader.fileConnect(); 19 | this.fileWriter.fileConnect(); 20 | 21 | } 22 | 23 | public void write(String content){ 24 | this.fileWriter.fileWrite(content); 25 | } 26 | 27 | public String read(){ 28 | return this.fileReader.fileRead(); 29 | } 30 | 31 | public void disConnect(){ 32 | this.fileReader.fileDisconnect(); 33 | this.fileWriter.fileDisconnect(); 34 | this.ftpProtocol.disConnect(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/observer/IButtonClickListener.java: -------------------------------------------------------------------------------- 1 | package com.company.design.observer; 2 | 3 | public interface IButtonClickListener { 4 | void clickEvent(String event); 5 | } 6 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/observer/MyButton.java: -------------------------------------------------------------------------------- 1 | package com.company.design.observer; 2 | 3 | public class MyButton { 4 | private String name; 5 | private IButtonClickListener buttonClickListener; 6 | 7 | public MyButton(String buttonName){ 8 | this.name = buttonName; 9 | } 10 | 11 | public void click(String clickEvent){ 12 | buttonClickListener.clickEvent(this.name+", "+clickEvent); 13 | } 14 | 15 | public void addListener(IButtonClickListener buttonClickListener){ 16 | this.buttonClickListener = buttonClickListener; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/proxy/Browser.java: -------------------------------------------------------------------------------- 1 | package com.company.design.proxy; 2 | 3 | public class Browser implements IBrowser { 4 | 5 | private String url; 6 | 7 | public Browser(String url){ 8 | this.url = url; 9 | } 10 | 11 | @Override 12 | public Html show() { 13 | System.out.println("Browser loading html from "+url); 14 | return new Html(url); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/proxy/BrowserProxy.java: -------------------------------------------------------------------------------- 1 | package com.company.design.proxy; 2 | 3 | public class BrowserProxy implements IBrowser { 4 | 5 | private String url; 6 | private Html html; 7 | 8 | public BrowserProxy(String url){ 9 | this.url = url; 10 | } 11 | 12 | @Override 13 | public Html show() { 14 | if(html == null){ 15 | this.html = new Html(url); 16 | System.out.println("BrowserProxy loading html from "+url); 17 | } 18 | System.out.println("BrowserProxy use cache html"); 19 | return html; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/proxy/Html.java: -------------------------------------------------------------------------------- 1 | package com.company.design.proxy; 2 | 3 | public class Html { 4 | private String url; 5 | 6 | public Html(String url){ 7 | this.url = url; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/proxy/IBroswer.java: -------------------------------------------------------------------------------- 1 | package com.company.design.proxy; 2 | 3 | public interface IBroswer { 4 | Html show(); 5 | } 6 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/proxy/IBrowser.java: -------------------------------------------------------------------------------- 1 | package com.company.design.proxy; 2 | 3 | public interface IBrowser { 4 | Html show(); 5 | } 6 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/singleton/AClazz.java: -------------------------------------------------------------------------------- 1 | package com.company.design.singleton; 2 | 3 | public class AClazz { 4 | 5 | public SocketClient getSocketClient() { 6 | return socketClient; 7 | } 8 | 9 | public void setSocketClient(SocketClient socketClient) { 10 | this.socketClient = socketClient; 11 | } 12 | 13 | private SocketClient socketClient; 14 | 15 | public AClazz(){ 16 | this.socketClient = SocketClient.getInstance(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/singleton/BClazz.java: -------------------------------------------------------------------------------- 1 | package com.company.design.singleton; 2 | 3 | public class BClazz { 4 | 5 | public SocketClient getSocketClient() { 6 | return socketClient; 7 | } 8 | 9 | public void setSocketClient(SocketClient socketClient) { 10 | this.socketClient = socketClient; 11 | } 12 | 13 | private SocketClient socketClient; 14 | 15 | public BClazz(){ 16 | this.socketClient = SocketClient.getInstance(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/singleton/SocketClient.java: -------------------------------------------------------------------------------- 1 | package com.company.design.singleton; 2 | 3 | public class SocketClient { 4 | 5 | private static SocketClient socketClient = null; 6 | 7 | // default 생성자 막기 8 | private SocketClient(){} 9 | 10 | public static SocketClient getInstance(){ 11 | 12 | if(socketClient == null){ 13 | socketClient = new SocketClient(); 14 | System.out.println("socket new instance"); 15 | } 16 | 17 | return socketClient; 18 | } 19 | 20 | public void connect(){ 21 | System.out.println("socket"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/strategy/Base64Strategy.java: -------------------------------------------------------------------------------- 1 | package com.company.design.strategy; 2 | 3 | import java.util.Base64; 4 | 5 | public class Base64Strategy implements EncodingStrategy{ 6 | @Override 7 | public String encoding(String message) { 8 | return Base64.getEncoder().encodeToString(message.getBytes()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/strategy/Encoder.java: -------------------------------------------------------------------------------- 1 | package com.company.design.strategy; 2 | 3 | public class Encoder { 4 | private EncodingStrategy encodingStrategy; 5 | 6 | public String getMessage(String message){ 7 | return encodingStrategy.encoding(message); 8 | } 9 | 10 | public void setEncodingStrategy(EncodingStrategy encodingStrategy){ 11 | this.encodingStrategy = encodingStrategy; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/strategy/EncodingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.company.design.strategy; 2 | 3 | public interface EncodingStrategy { 4 | String encoding(String message); 5 | } 6 | -------------------------------------------------------------------------------- /02. 디자인패턴/SourceCode/design-pattern/src/com/company/design/strategy/NormalStrategy.java: -------------------------------------------------------------------------------- 1 | package com.company.design.strategy; 2 | 3 | public class NormalStrategy implements EncodingStrategy{ 4 | @Override 5 | public String encoding(String message) { 6 | return message; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /02. 디자인패턴/강의자료/02. 디자인패턴.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/02. 디자인패턴/강의자료/02. 디자인패턴.pdf -------------------------------------------------------------------------------- /03. 웹 개발 개론/강의자료/03. 웹개발개론.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/03. 웹 개발 개론/강의자료/03. 웹개발개론.pdf -------------------------------------------------------------------------------- /04. Spring Boot 시작하기/강의자료/04. Spring Boot 시작하기.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/04. Spring Boot 시작하기/강의자료/04. Spring Boot 시작하기.pdf -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-aop' 17 | implementation 'org.springframework.boot:spring-boot-starter-web' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | } 24 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/SourceCode/aop/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'aop' 2 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/AopApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.aop; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import java.util.Base64; 7 | 8 | @SpringBootApplication 9 | public class AopApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AopApplication.class, args); 13 | System.out.println(Base64.getEncoder().encodeToString("steve@gmail.com".getBytes())); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/annotation/Decode.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE, ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Decode { 11 | } 12 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/annotation/Timer.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE, ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Timer { 11 | } 12 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/aop/DecodeAop.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.aop; 2 | 3 | import com.example.aop.dto.User; 4 | import org.aspectj.lang.JoinPoint; 5 | import org.aspectj.lang.annotation.AfterReturning; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Before; 8 | import org.aspectj.lang.annotation.Pointcut; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.io.UnsupportedEncodingException; 12 | import java.util.Base64; 13 | 14 | @Aspect 15 | @Component 16 | public class DecodeAop { 17 | 18 | @Pointcut("execution(* com.example.aop.controller..*.*(..))") 19 | private void cut(){} 20 | 21 | @Pointcut("@annotation(com.example.aop.annotation.Decode)") 22 | private void enableDecode(){} 23 | 24 | 25 | @Before("cut() && enableDecode()") 26 | public void before(JoinPoint joinPoint) throws UnsupportedEncodingException { 27 | Object[] args = joinPoint.getArgs(); 28 | for(Object arg : args){ 29 | if(arg instanceof User){ 30 | User user = User.class.cast(arg); 31 | String base64Email = user.getEmail(); 32 | String email = new String(Base64.getDecoder().decode(base64Email),"UTF-8"); 33 | user.setEmail(email); 34 | } 35 | } 36 | } 37 | 38 | @AfterReturning(value = "cut() && enableDecode()", returning = "returnObj") 39 | public void afterReturn(JoinPoint joinPoint, Object returnObj){ 40 | if(returnObj instanceof User){ 41 | User user = User.class.cast(returnObj); 42 | String email = user.getEmail(); 43 | String base64Email = Base64.getEncoder().encodeToString(email.getBytes()); 44 | user.setEmail(base64Email); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/aop/ParameterAop.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.aop; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.annotation.AfterReturning; 5 | import org.aspectj.lang.annotation.Aspect; 6 | import org.aspectj.lang.annotation.Before; 7 | import org.aspectj.lang.annotation.Pointcut; 8 | import org.aspectj.lang.reflect.MethodSignature; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.lang.reflect.Method; 12 | 13 | @Aspect 14 | @Component 15 | public class ParameterAop { 16 | 17 | @Pointcut("execution(* com.example.aop.controller..*.*(..))") 18 | private void cut(){} 19 | 20 | @Before("cut()") 21 | public void before(JoinPoint joinPoint){ 22 | MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); 23 | Method method = methodSignature.getMethod(); 24 | System.out.println(method.getName()); 25 | Object[] args = joinPoint.getArgs(); 26 | for(Object obj : args){ 27 | System.out.println("type : "+obj.getClass().getSimpleName()); 28 | System.out.println("value : "+obj); 29 | } 30 | } 31 | 32 | @AfterReturning(value = "cut()", returning = "returnObj") 33 | public void afterReturn(JoinPoint joinPoint, Object returnObj){ 34 | System.out.println("return obj"); 35 | System.out.println(returnObj); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/aop/TimerAop.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.aop; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.annotation.Around; 5 | import org.aspectj.lang.annotation.Aspect; 6 | import org.aspectj.lang.annotation.Pointcut; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.util.StopWatch; 10 | 11 | @Aspect 12 | @Component 13 | public class TimerAop { 14 | 15 | @Pointcut("execution(* com.example.aop.controller..*.*(..))") 16 | private void cut(){} 17 | 18 | @Pointcut("@annotation(com.example.aop.annotation.Timer)") 19 | private void enableTimer(){} 20 | 21 | @Around("cut() && enableTimer()") 22 | public void around(ProceedingJoinPoint joinPoint) throws Throwable { 23 | StopWatch stopWatch = new StopWatch(); 24 | stopWatch.start(); 25 | 26 | Object result = joinPoint.proceed(); 27 | 28 | stopWatch.stop(); 29 | System.out.println("total time : "+stopWatch.getTotalTimeSeconds()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/controller/RestApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.controller; 2 | 3 | import com.example.aop.annotation.Decode; 4 | import com.example.aop.annotation.Timer; 5 | import com.example.aop.dto.User; 6 | import org.springframework.util.StopWatch; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | @RestController 10 | @RequestMapping("/api") 11 | public class RestApiController { 12 | 13 | @GetMapping("/get/{id}") 14 | public String get(@PathVariable Long id, @RequestParam String name){ 15 | // TODO 16 | 17 | return id+ " "+ name; 18 | } 19 | 20 | @PostMapping("/post") 21 | public User post(@RequestBody User user){ 22 | 23 | 24 | return user; 25 | } 26 | 27 | @Timer 28 | @DeleteMapping("/delete") 29 | public void delete() throws InterruptedException { 30 | 31 | // db logic 32 | Thread.sleep(1000 * 2); 33 | 34 | } 35 | 36 | @Decode 37 | @PutMapping("/put") 38 | public User put(@RequestBody User user){ 39 | System.out.println("put"); 40 | System.out.println(user); 41 | return user; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/java/com/example/aop/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.dto; 2 | 3 | public class User { 4 | 5 | private String id; 6 | private String pw; 7 | private String email; 8 | 9 | public String getId() { 10 | return id; 11 | } 12 | 13 | public void setId(String id) { 14 | this.id = id; 15 | } 16 | 17 | public String getPw() { 18 | return pw; 19 | } 20 | 21 | public void setPw(String pw) { 22 | this.pw = pw; 23 | } 24 | 25 | public String getEmail() { 26 | return email; 27 | } 28 | 29 | public void setEmail(String email) { 30 | this.email = email; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "User{" + 36 | "id='" + id + '\'' + 37 | ", pw='" + pw + '\'' + 38 | ", email='" + email + '\'' + 39 | '}'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/aop/src/test/java/com/example/aop/AopApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.aop; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AopApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../../../:\Users\fc\IdeaProjects\ioc\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/.idea/description.html: -------------------------------------------------------------------------------- 1 | Simple Java application that includes a class with main() method -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/ioc.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/src/com/company/ioc/Base64Encoder.java: -------------------------------------------------------------------------------- 1 | package com.company.ioc; 2 | 3 | import java.util.Base64; 4 | 5 | public class Base64Encoder implements IEncoder{ 6 | 7 | public String encode(String message){ 8 | return Base64.getEncoder().encodeToString(message.getBytes()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/src/com/company/ioc/Encoder.java: -------------------------------------------------------------------------------- 1 | package com.company.ioc; 2 | 3 | public class Encoder { 4 | 5 | private IEncoder iEncoder; 6 | 7 | public Encoder(IEncoder iEncoder){ 8 | this.iEncoder = iEncoder; 9 | } 10 | 11 | public String encode(String message){ 12 | return iEncoder.encode(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/src/com/company/ioc/IEncoder.java: -------------------------------------------------------------------------------- 1 | package com.company.ioc; 2 | 3 | public interface IEncoder { 4 | String encode(String message); 5 | } 6 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/src/com/company/ioc/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.ioc; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | String url = "www.naver.com/books/it?page=10&size=20&name=spring-boot"; 7 | 8 | Encoder encoder = new Encoder(new Base64Encoder()); 9 | String result = encoder.encode(url); 10 | System.out.println(result); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/ioc/src/com/company/ioc/UrlEncoder.java: -------------------------------------------------------------------------------- 1 | package com.company.ioc; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.net.URLEncoder; 5 | 6 | public class UrlEncoder implements IEncoder{ 7 | 8 | public String encode(String message){ 9 | try { 10 | return URLEncoder.encode(message, "UTF-8"); 11 | } catch (UnsupportedEncodingException e) { 12 | e.printStackTrace(); 13 | return null; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | group 'org.example' 6 | version '1.0-SNAPSHOT' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind 14 | implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1' 15 | testCompile group: 'junit', name: 'junit', version: '4.12' 16 | } 17 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/SourceCode/object-mapper/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'object-mapper' 2 | 3 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import com.fasterxml.jackson.core.JsonProcessingException; 2 | import com.fasterxml.jackson.core.type.TypeReference; 3 | import com.fasterxml.jackson.databind.DeserializationConfig; 4 | import com.fasterxml.jackson.databind.DeserializationFeature; 5 | import com.fasterxml.jackson.databind.JsonNode; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.fasterxml.jackson.databind.node.ArrayNode; 8 | import com.fasterxml.jackson.databind.node.ObjectNode; 9 | import dto.Car; 10 | import dto.User; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class Main { 16 | 17 | public static void main(String args[]) throws JsonProcessingException { 18 | ObjectMapper objectMapper = new ObjectMapper(); 19 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 20 | User user = new User(); 21 | user.setAge(10); 22 | user.setName("홍길동"); 23 | 24 | Car car1 = new Car(); 25 | car1.setName("AUDI"); 26 | car1.setNumber("1111"); 27 | 28 | Car car2 = new Car(); 29 | car2.setName("BMW"); 30 | car2.setNumber("2222"); 31 | 32 | List carList = Arrays.asList(car1, car2); 33 | user.setCar(carList); 34 | 35 | String json = objectMapper.writeValueAsString(user); 36 | System.out.println(json); 37 | 38 | User parsing = objectMapper.readValue(json, User.class); 39 | System.out.println(parsing); 40 | 41 | // node parsing 42 | 43 | JsonNode jsonNode = objectMapper.readTree(json); 44 | String name = jsonNode.get("name").asText(); 45 | int age = jsonNode.get("age").asInt(); 46 | JsonNode cars = jsonNode.get("car"); 47 | ArrayNode arrayNode = (ArrayNode)cars; 48 | System.out.println(name); 49 | System.out.println(age); 50 | List _car = objectMapper.convertValue(arrayNode, new TypeReference>() {}); 51 | System.out.println(_car); 52 | 53 | 54 | ObjectNode objectNode = (ObjectNode)jsonNode; 55 | objectNode.put("name","abcd"); 56 | System.out.println(objectNode.toPrettyString()); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/src/main/java/dto/Car.java: -------------------------------------------------------------------------------- 1 | package dto; 2 | 3 | public class Car { 4 | private String name; 5 | private String number; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public String getNumber() { 16 | return number; 17 | } 18 | 19 | public void setNumber(String number) { 20 | this.number = number; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "Car{" + 26 | "name='" + name + '\'' + 27 | ", number='" + number + '\'' + 28 | '}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/object-mapper/src/main/java/dto/User.java: -------------------------------------------------------------------------------- 1 | package dto; 2 | 3 | import java.util.List; 4 | 5 | public class User { 6 | public String getName() { 7 | return name; 8 | } 9 | 10 | public void setName(String name) { 11 | this.name = name; 12 | } 13 | 14 | public int getAge() { 15 | return age; 16 | } 17 | 18 | public void setAge(int age) { 19 | this.age = age; 20 | } 21 | 22 | public List getCar() { 23 | return car; 24 | } 25 | 26 | public void setCar(List car) { 27 | this.car = car; 28 | } 29 | 30 | private String name; 31 | private int age; 32 | private List car; 33 | 34 | @Override 35 | public String toString() { 36 | return "User{" + 37 | "name='" + name + '\'' + 38 | ", age=" + age + 39 | ", car=" + car + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | } 23 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'ioc' 2 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/java/com/example/ioc/ApplicationContextProvider.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class ApplicationContextProvider implements ApplicationContextAware { 10 | 11 | private static ApplicationContext context; 12 | 13 | @Override 14 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 15 | context = applicationContext; 16 | } 17 | 18 | public static ApplicationContext getContext(){ 19 | return context; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/java/com/example/ioc/Base64Encoder.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.util.Base64; 6 | 7 | @Component("base74Encoder") 8 | public class Base64Encoder implements IEncoder { 9 | 10 | public String encode(String message){ 11 | return Base64.getEncoder().encodeToString(message.getBytes()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/java/com/example/ioc/Encoder.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | import org.springframework.beans.factory.annotation.Qualifier; 4 | import org.springframework.stereotype.Component; 5 | 6 | public class Encoder { 7 | 8 | private IEncoder iEncoder; 9 | 10 | public Encoder(IEncoder iEncoder){ 11 | this.iEncoder = iEncoder; 12 | } 13 | 14 | public void setIEncoder(IEncoder iEncoder){ 15 | this.iEncoder = iEncoder; 16 | } 17 | 18 | public String encode(String message){ 19 | return iEncoder.encode(message); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/java/com/example/ioc/IEncoder.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | public interface IEncoder { 4 | String encode(String message); 5 | } 6 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/java/com/example/ioc/IocApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @SpringBootApplication 10 | public class IocApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(IocApplication.class, args); 14 | ApplicationContext context = ApplicationContextProvider.getContext(); 15 | 16 | //Base64Encoder base64Encoder = context.getBean(Base64Encoder.class); 17 | //UrlEncoder urlEncoder = context.getBean(UrlEncoder.class); 18 | 19 | Encoder encoder = context.getBean("urlEncode", Encoder.class); 20 | String url = "www.naver.com/books/it?page=10&size=20&name=spring-boot"; 21 | String result = encoder.encode(url); 22 | System.out.println(result); 23 | } 24 | 25 | } 26 | 27 | @Configuration 28 | class AppConfig{ 29 | 30 | @Bean("base64Encode") 31 | public Encoder encoder(Base64Encoder base64Encoder){ 32 | return new Encoder(base64Encoder); 33 | } 34 | 35 | @Bean("urlEncode") 36 | public Encoder encoder(UrlEncoder urlEncoder){ 37 | return new Encoder(urlEncoder); 38 | } 39 | } -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/java/com/example/ioc/UrlEncoder.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.io.UnsupportedEncodingException; 6 | import java.net.URLEncoder; 7 | 8 | @Component 9 | public class UrlEncoder implements IEncoder { 10 | 11 | public String encode(String message){ 12 | try { 13 | return URLEncoder.encode(message, "UTF-8"); 14 | } catch (UnsupportedEncodingException e) { 15 | e.printStackTrace(); 16 | return null; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/SourceCode/spring-ioc/src/test/java/com/example/ioc/IocApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.ioc; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class IocApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/강의자료/01. 스프링의 핵심/01. 스프링의 핵심.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/강의자료/01. 스프링의 핵심/01. 스프링의 핵심.pdf -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/강의자료/02. IoC-DI/02. IoC-DI.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/강의자료/02. IoC-DI/02. IoC-DI.pdf -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/강의자료/03. AOP/03. AOP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/강의자료/03. AOP/03. AOP.pdf -------------------------------------------------------------------------------- /05. Spring 조금 더 들여다보기/강의자료/07. 여러가지 Annotation/07. 여러가지 Annotation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/05. Spring 조금 더 들여다보기/강의자료/07. 여러가지 Annotation/07. 여러가지 Annotation.pdf -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '1.8' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | } 23 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/SourceCode/async/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'async' 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/src/main/java/com/example/async/AsyncApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.async; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | 7 | @SpringBootApplication 8 | @EnableAsync 9 | public class AsyncApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AsyncApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/src/main/java/com/example/async/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.async.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 6 | 7 | import java.util.concurrent.Executor; 8 | 9 | @Configuration 10 | public class AppConfig { 11 | 12 | @Bean("asyncThread") 13 | public Executor asyncThread(){ 14 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 15 | executor.setCorePoolSize(10); 16 | executor.setMaxPoolSize(100); 17 | executor.setQueueCapacity(10); 18 | executor.setThreadNamePrefix("Async-"); 19 | return executor; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/src/main/java/com/example/async/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.async.controller; 2 | 3 | import com.example.async.service.TaskService; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.scheduling.annotation.Async; 8 | import org.springframework.util.concurrent.ListenableFuture; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.concurrent.CompletableFuture; 14 | import java.util.concurrent.ExecutionException; 15 | 16 | @RestController 17 | @RequestMapping("/api") 18 | public class ApiController { 19 | 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | 22 | @Autowired 23 | private TaskService taskService; 24 | 25 | @GetMapping("/hello") 26 | public String hello() { 27 | logger.info("Thread Start"); 28 | 29 | for(int i = 0 ; i < 10; i ++){ 30 | //async(i); 31 | taskService.run(i); 32 | } 33 | 34 | logger.info("Thread end"); 35 | return "response hello"; 36 | } 37 | 38 | @GetMapping("/future") 39 | public ListenableFuture listenableFuture() throws InterruptedException, ExecutionException { 40 | logger.info("future Start"); 41 | logger.info("future end"); 42 | return taskService.listenableFuture(10000); 43 | } 44 | 45 | @GetMapping("/completableFuture") 46 | public CompletableFuture completableFuture() throws Exception { 47 | logger.info("completableFuture Start"); 48 | logger.info("completableFuture end"); 49 | return taskService.completableFuture(1000); 50 | } 51 | 52 | @Async 53 | public void async(int i){ 54 | logger.info("in method : {}",i); 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/src/main/java/com/example/async/service/TaskService.java: -------------------------------------------------------------------------------- 1 | package com.example.async.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.scheduling.annotation.Async; 7 | import org.springframework.scheduling.annotation.AsyncResult; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.util.concurrent.ListenableFuture; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.concurrent.CompletableFuture; 13 | import java.util.concurrent.Executor; 14 | 15 | @Service 16 | public class TaskService { 17 | 18 | @Resource(name = "asyncThread") 19 | private Executor executor; 20 | 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | 23 | @Async("asyncThread") 24 | public void run(int i) { 25 | logger.info("count : {}",i); 26 | } 27 | 28 | @Async("asyncThread") 29 | public ListenableFuture listenableFuture(int i) throws InterruptedException { 30 | Thread.sleep(1000); 31 | logger.info("----------------"); 32 | return new AsyncResult<>(i); 33 | } 34 | 35 | @Async("asyncThread") 36 | public CompletableFuture completableFuture(int i) throws InterruptedException { 37 | /*CompletableFuture completableFuture = CompletableFuture.supplyAsync(()-> hello(),executor); 38 | completableFuture.thenApplyAsync(s -> { 39 | try { 40 | Thread.sleep(4000); 41 | } catch (InterruptedException e) { 42 | e.printStackTrace(); 43 | } 44 | logger.info("completable : {}",s); 45 | return "completable"; 46 | },executor);*/ 47 | 48 | return new AsyncResult(hello()).completable(); 49 | } 50 | 51 | public String hello() { 52 | logger.info("hello Method Call"); 53 | try { 54 | Thread.sleep(1000); 55 | } catch (InterruptedException e) { 56 | e.printStackTrace(); 57 | } 58 | return "hellosss"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/async/src/test/java/com/example/async/AsyncApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.async; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AsyncApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | implementation 'org.springframework.boot:spring-boot-starter-validation' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | } 24 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/SourceCode/exception/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'exception' 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/main/java/com/example/exception/ExceptionApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.exception; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ExceptionApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ExceptionApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/main/java/com/example/exception/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.exception.controller; 2 | 3 | import com.example.exception.dto.User; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.validation.annotation.Validated; 7 | import org.springframework.web.bind.MethodArgumentNotValidException; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import javax.validation.Valid; 11 | import javax.validation.constraints.Min; 12 | import javax.validation.constraints.NotNull; 13 | import javax.validation.constraints.Size; 14 | 15 | @RestController 16 | @RequestMapping("/api/user") 17 | @Validated 18 | public class ApiController { 19 | 20 | @GetMapping("") // ?name=1234 21 | public User get( 22 | @Size(min = 2) 23 | @RequestParam String name, 24 | 25 | @NotNull 26 | @Min(1) 27 | @RequestParam Integer age){ 28 | User user = new User(); 29 | user.setName(name); 30 | user.setAge(age); 31 | 32 | return user; 33 | } 34 | 35 | 36 | @PostMapping("") 37 | public User post(@Valid @RequestBody User user){ 38 | System.out.println(user); 39 | return user; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/main/java/com/example/exception/dto/Error.java: -------------------------------------------------------------------------------- 1 | package com.example.exception.dto; 2 | 3 | public class Error { 4 | 5 | private String field; 6 | private String message; 7 | private String invalidValue; 8 | 9 | public String getField() { 10 | return field; 11 | } 12 | 13 | public void setField(String field) { 14 | this.field = field; 15 | } 16 | 17 | public String getMessage() { 18 | return message; 19 | } 20 | 21 | public void setMessage(String message) { 22 | this.message = message; 23 | } 24 | 25 | public String getInvalidValue() { 26 | return invalidValue; 27 | } 28 | 29 | public void setInvalidValue(String invalidValue) { 30 | this.invalidValue = invalidValue; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/main/java/com/example/exception/dto/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | package com.example.exception.dto; 2 | 3 | import java.util.List; 4 | 5 | public class ErrorResponse { 6 | 7 | String statusCode; 8 | String requestUrl; 9 | String code; 10 | String message; 11 | String resultCode; 12 | 13 | List errorList; 14 | 15 | public String getStatusCode() { 16 | return statusCode; 17 | } 18 | 19 | public void setStatusCode(String statusCode) { 20 | this.statusCode = statusCode; 21 | } 22 | 23 | public String getRequestUrl() { 24 | return requestUrl; 25 | } 26 | 27 | public void setRequestUrl(String requestUrl) { 28 | this.requestUrl = requestUrl; 29 | } 30 | 31 | public String getCode() { 32 | return code; 33 | } 34 | 35 | public void setCode(String code) { 36 | this.code = code; 37 | } 38 | 39 | public String getMessage() { 40 | return message; 41 | } 42 | 43 | public void setMessage(String message) { 44 | this.message = message; 45 | } 46 | 47 | public String getResultCode() { 48 | return resultCode; 49 | } 50 | 51 | public void setResultCode(String resultCode) { 52 | this.resultCode = resultCode; 53 | } 54 | 55 | public List getErrorList() { 56 | return errorList; 57 | } 58 | 59 | public void setErrorList(List errorList) { 60 | this.errorList = errorList; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/main/java/com/example/exception/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.exception.dto; 2 | 3 | import javax.validation.constraints.Min; 4 | import javax.validation.constraints.NotEmpty; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Size; 7 | 8 | public class User { 9 | 10 | @NotEmpty 11 | @Size(min = 1, max = 10) 12 | private String name; 13 | 14 | @Min(1) 15 | @NotNull 16 | private Integer age; 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public int getAge() { 27 | return age; 28 | } 29 | 30 | public void setAge(int age) { 31 | this.age = age; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "User{" + 37 | "name='" + name + '\'' + 38 | ", age=" + age + 39 | '}'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/exception/src/test/java/com/example/exception/ExceptionApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.exception; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ExceptionApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '1.8' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 18 | } 19 | 20 | test { 21 | useJUnitPlatform() 22 | } 23 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'filterandinterceptor' 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/FilterandinterceptorApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.ServletComponentScan; 6 | 7 | @SpringBootApplication 8 | @ServletComponentScan 9 | public class FilterandinterceptorApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(FilterandinterceptorApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/annotation/AuthUser.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Target({ ElementType.TYPE, ElementType.METHOD }) 8 | public @interface AuthUser { 9 | } 10 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/config/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor.config; 2 | 3 | import com.example.filterandinterceptor.interceptor.AuthInterceptor; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | @Configuration 10 | public class MvcConfig implements WebMvcConfigurer { 11 | 12 | private static final String[] DEFAULT_EXCLUDE_PATH = { 13 | "/api/ping", 14 | }; 15 | 16 | private final AuthInterceptor authInterceptor; 17 | 18 | public MvcConfig(AuthInterceptor authInterceptor) { 19 | this.authInterceptor = authInterceptor; 20 | } 21 | 22 | 23 | 24 | @Override 25 | public void addInterceptors(InterceptorRegistry registry) { 26 | registry.addInterceptor(authInterceptor); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor.controller; 2 | 3 | import com.example.filterandinterceptor.annotation.AuthUser; 4 | import com.example.filterandinterceptor.dto.User; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | @AuthUser 9 | @RestController 10 | @RequestMapping("/api") 11 | public class ApiController { 12 | 13 | @PostMapping("/post") 14 | public User post(@RequestBody User user){ 15 | return user; 16 | } 17 | 18 | @DeleteMapping("/delete") 19 | public ResponseEntity post(){ 20 | return ResponseEntity.ok().build(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor.dto; 2 | 3 | public class User { 4 | 5 | private String name; 6 | private int age; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public int getAge() { 17 | return age; 18 | } 19 | 20 | public void setAge(int age) { 21 | this.age = age; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "User{" + 27 | "name='" + name + '\'' + 28 | ", age=" + age + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/filter/RequestFilter.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor.filter; 2 | 3 | import org.springframework.web.util.ContentCachingRequestWrapper; 4 | import org.springframework.web.util.ContentCachingResponseWrapper; 5 | 6 | import javax.servlet.*; 7 | import javax.servlet.annotation.WebFilter; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | @WebFilter(urlPatterns = "/api/*") 13 | public class RequestFilter implements Filter { 14 | @Override 15 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 16 | ContentCachingRequestWrapper wrappingRequest = new ContentCachingRequestWrapper((HttpServletRequest)request); 17 | ContentCachingResponseWrapper wrappingResponse = new ContentCachingResponseWrapper((HttpServletResponse) response); 18 | 19 | chain.doFilter(wrappingRequest, wrappingResponse); 20 | 21 | System.out.println("---req ---"); 22 | System.out.println(new String(wrappingRequest.getContentAsByteArray(),"UTF-8")); 23 | byte[] b = wrappingRequest.getContentAsByteArray(); 24 | System.out.println("---req ---"); 25 | 26 | System.out.println("---res ---"); 27 | System.out.println(new String(wrappingResponse.getContentAsByteArray(),"UTF-8")); 28 | System.out.println("---res ---"); 29 | wrappingResponse.copyBodyToResponse(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/java/com/example/filterandinterceptor/interceptor/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor.interceptor; 2 | 3 | import com.example.filterandinterceptor.annotation.AuthUser; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.method.HandlerMethod; 6 | import org.springframework.web.servlet.HandlerInterceptor; 7 | import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | @Component 13 | public class AuthInterceptor implements HandlerInterceptor { 14 | 15 | @Override 16 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 17 | 18 | boolean validAuthUser = checkValidAccessAnnotation(handler, AuthUser.class); 19 | System.out.println("annotation check : "+validAuthUser); 20 | if(validAuthUser){ 21 | return true; 22 | } 23 | 24 | return false; 25 | } 26 | 27 | private boolean checkValidAccessAnnotation(Object handler, Class clazz) { 28 | 29 | if(handler instanceof ResourceHttpRequestHandler){ 30 | System.out.println("리소스 요청 class "+clazz.getName()); 31 | return true; 32 | } 33 | 34 | HandlerMethod handlerMethod = (HandlerMethod) handler; 35 | if(null != handlerMethod.getMethodAnnotation(clazz) || null != handlerMethod.getBeanType().getAnnotation(clazz)){ 36 | System.out.println("어노테이션 체크 class "+clazz.getName()); 37 | return true; 38 | } 39 | 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/filter-and-interceptor/src/test/java/com/example/filterandinterceptor/FilterandinterceptorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.filterandinterceptor; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FilterandinterceptorApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../../../:\Users\Fastcampus\IdeaProjects\object_mapper\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/.idea/modules/object_mapper.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | group 'org.example' 6 | version '1.0-SNAPSHOT' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind 14 | implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1' 15 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' 16 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' 17 | } 18 | 19 | test { 20 | useJUnitPlatform() 21 | } -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/build/tmp/compileJava/source-classes-mapping.txt: -------------------------------------------------------------------------------- 1 | dto/User.java 2 | dto.User 3 | dto/Car.java 4 | dto.Car 5 | Main.java 6 | Main 7 | Main$1 8 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"홍길동", 3 | "age":10, 4 | "cars":[ 5 | { 6 | "name":"K5", 7 | "carNumber":"11가 1111", 8 | "type":"sedan" 9 | }, 10 | { 11 | "name":"Q5", 12 | "carNumber":"22가 2222", 13 | "type":"SUV" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'object_mapper' 2 | 3 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import com.fasterxml.jackson.core.JsonProcessingException; 2 | import com.fasterxml.jackson.core.type.TypeReference; 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.databind.node.ArrayNode; 6 | import com.fasterxml.jackson.databind.node.ObjectNode; 7 | import dto.Car; 8 | import dto.User; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class Main { 14 | 15 | public static void main(String args[]) throws JsonProcessingException { 16 | System.out.println("main"); 17 | ObjectMapper objectMapper = new ObjectMapper(); 18 | User user = new User(); 19 | user.setName("홍길동"); 20 | user.setAge(10); 21 | 22 | Car car1 = new Car(); 23 | car1.setName("K5"); 24 | car1.setCarNumber("11가 1111"); 25 | car1.setType("sedan"); 26 | 27 | Car car2 = new Car(); 28 | car2.setName("Q5"); 29 | car2.setCarNumber("22가 2222"); 30 | car2.setType("SUV"); 31 | List carList = Arrays.asList(car1, car2); 32 | user.setCars(carList); 33 | 34 | //System.out.println(user); 35 | 36 | String json = objectMapper.writeValueAsString(user); 37 | System.out.println(json); 38 | 39 | JsonNode jsonNode = objectMapper.readTree(json); 40 | String _name = jsonNode.get("name").asText(); 41 | int _age = jsonNode.get("age").asInt(); 42 | System.out.println("name : "+_name); 43 | System.out.println("age : "+_age); 44 | 45 | JsonNode cars = jsonNode.get("cars"); 46 | ArrayNode arrayNode = (ArrayNode)cars; 47 | 48 | List _cars = objectMapper.convertValue(arrayNode, new TypeReference>(){}); 49 | System.out.println(_cars); 50 | 51 | ObjectNode objectNode = (ObjectNode) jsonNode; 52 | objectNode.put("name","steve"); 53 | objectNode.put("age",20); 54 | 55 | System.out.println(objectNode.toPrettyString()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/src/main/java/dto/Car.java: -------------------------------------------------------------------------------- 1 | package dto; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class Car { 6 | private String name; 7 | 8 | @JsonProperty("car_number") 9 | private String carNumber; 10 | 11 | @JsonProperty("TYPE") 12 | private String type; 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getCarNumber() { 23 | return carNumber; 24 | } 25 | 26 | public void setCarNumber(String carNumber) { 27 | this.carNumber = carNumber; 28 | } 29 | 30 | public String getType() { 31 | return type; 32 | } 33 | 34 | public void setType(String type) { 35 | this.type = type; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Car{" + 41 | "name='" + name + '\'' + 42 | ", carNumber='" + carNumber + '\'' + 43 | ", type='" + type + '\'' + 44 | '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/object_mapper/src/main/java/dto/User.java: -------------------------------------------------------------------------------- 1 | package dto; 2 | 3 | import java.util.List; 4 | 5 | public class User { 6 | 7 | private String name; 8 | private int age; 9 | private List cars; 10 | 11 | public List getCars() { 12 | return cars; 13 | } 14 | 15 | public void setCars(List cars) { 16 | this.cars = cars; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public int getAge() { 28 | return age; 29 | } 30 | 31 | public void setAge(int age) { 32 | this.age = age; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "User{" + 38 | "name='" + name + '\'' + 39 | ", age=" + age + 40 | ", cars=" + cars + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | implementation 'org.springframework.boot:spring-boot-starter-validation' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | 21 | test { 22 | useJUnitPlatform() 23 | } 24 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/SourceCode/validation/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'validation' 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/ValidationApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.validation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ValidationApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ValidationApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/annotation/YearMonth.java: -------------------------------------------------------------------------------- 1 | package com.example.validation.annotation; 2 | 3 | import com.example.validation.validator.YearMonthValidator; 4 | 5 | import javax.validation.Constraint; 6 | import javax.validation.Payload; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.Target; 9 | 10 | import static java.lang.annotation.ElementType.*; 11 | import static java.lang.annotation.ElementType.TYPE_USE; 12 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 13 | 14 | @Constraint(validatedBy = {YearMonthValidator.class}) 15 | @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) 16 | @Retention(RUNTIME) 17 | public @interface YearMonth { 18 | 19 | String message() default "yyyyMM 형식에 맞지 않습니다."; 20 | 21 | Class[] groups() default { }; 22 | 23 | Class[] payload() default { }; 24 | 25 | String pattern() default "yyyyMMdd"; 26 | } 27 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.validation.controller; 2 | 3 | import com.example.validation.dto.Req; 4 | import com.example.validation.dto.User; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.validation.BindingResult; 8 | import org.springframework.validation.FieldError; 9 | import org.springframework.validation.annotation.Validated; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import javax.validation.Valid; 13 | import javax.validation.constraints.*; 14 | 15 | @RestController 16 | @RequestMapping("/api") 17 | @Validated 18 | public class ApiController { 19 | 20 | @GetMapping("") 21 | public String get( 22 | /* @Size(min = 1 , max = 10) 23 | @NotEmpty 24 | @RequestParam String name, 25 | 26 | @Min(10) 27 | @RequestParam int age 28 | 29 | */ 30 | @Valid Req req 31 | ){ 32 | return req.getName() + req.getAge(); 33 | } 34 | 35 | @PostMapping("/user") 36 | public ResponseEntity user(@Valid @RequestBody User user, BindingResult bindingResult){ 37 | 38 | if(bindingResult.hasErrors()){ 39 | StringBuilder sb = new StringBuilder(); 40 | bindingResult.getAllErrors().forEach(objectError -> { 41 | FieldError field = (FieldError) objectError; 42 | String message = objectError.getDefaultMessage(); 43 | 44 | System.out.println("field : "+field.getField()); 45 | System.out.println(message); 46 | 47 | sb.append("field : "+field.getField()); 48 | sb.append("message : "+message); 49 | 50 | }); 51 | 52 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(sb.toString()); 53 | } 54 | 55 | 56 | return ResponseEntity.ok(user); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/dto/Car.java: -------------------------------------------------------------------------------- 1 | package com.example.validation.dto; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | public class Car { 8 | 9 | @NotBlank 10 | private String name; 11 | 12 | @NotBlank 13 | @JsonProperty("car_number") 14 | private String carNumber; 15 | 16 | @NotBlank 17 | @JsonProperty("TYPE") 18 | private String type; 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public String getCarNumber() { 29 | return carNumber; 30 | } 31 | 32 | public void setCarNumber(String carNumber) { 33 | this.carNumber = carNumber; 34 | } 35 | 36 | public String getType() { 37 | return type; 38 | } 39 | 40 | public void setType(String type) { 41 | this.type = type; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "Car{" + 47 | "name='" + name + '\'' + 48 | ", carNumber='" + carNumber + '\'' + 49 | ", type='" + type + '\'' + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/dto/Req.java: -------------------------------------------------------------------------------- 1 | package com.example.validation.dto; 2 | 3 | import javax.validation.constraints.Min; 4 | import javax.validation.constraints.NotEmpty; 5 | import javax.validation.constraints.Size; 6 | 7 | public class Req { 8 | 9 | @Size(min = 1 , max = 10) 10 | @NotEmpty 11 | private String name; 12 | 13 | @Min(10) 14 | private int age; 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | public int getAge() { 25 | return age; 26 | } 27 | 28 | public void setAge(int age) { 29 | this.age = age; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.validation.dto; 2 | 3 | import com.example.validation.annotation.YearMonth; 4 | 5 | import javax.validation.Valid; 6 | import javax.validation.constraints.*; 7 | import java.util.List; 8 | 9 | public class User { 10 | 11 | @NotBlank 12 | private String name; 13 | 14 | @Max(value = 90) 15 | private int age; 16 | 17 | @Valid 18 | private List cars; 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public int getAge() { 29 | return age; 30 | } 31 | 32 | public void setAge(int age) { 33 | this.age = age; 34 | } 35 | 36 | public List getCars() { 37 | return cars; 38 | } 39 | 40 | public void setCars(List cars) { 41 | this.cars = cars; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "User{" + 47 | "name='" + name + '\'' + 48 | ", age=" + age + 49 | ", cars=" + cars + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/java/com/example/validation/validator/YearMonthValidator.java: -------------------------------------------------------------------------------- 1 | package com.example.validation.validator; 2 | 3 | import com.example.validation.annotation.YearMonth; 4 | 5 | import javax.validation.ConstraintValidator; 6 | import javax.validation.ConstraintValidatorContext; 7 | import java.time.LocalDate; 8 | import java.time.format.DateTimeFormatter; 9 | 10 | public class YearMonthValidator implements ConstraintValidator { 11 | 12 | private String pattern; 13 | 14 | @Override 15 | public void initialize(YearMonth constraintAnnotation) { 16 | this.pattern = constraintAnnotation.pattern(); 17 | } 18 | 19 | @Override 20 | public boolean isValid(String value, ConstraintValidatorContext context) { 21 | 22 | // yyyyMM 23 | try{ 24 | LocalDate localDate = LocalDate.parse(value+"01" , DateTimeFormatter.ofPattern(this.pattern)); 25 | }catch (Exception e){ 26 | return false; 27 | } 28 | 29 | 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/SourceCode/validation/src/test/java/com/example/validation/ValidationApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.validation; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ValidationApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/강의자료/01. Spring Boot Validation/01. Spring Boot Validation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/강의자료/01. Spring Boot Validation/01. Spring Boot Validation.pdf -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/강의자료/02. Spring Boot Custom Validation/02. Spring Boot Custom Validation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/강의자료/02. Spring Boot Custom Validation/02. Spring Boot Custom Validation.pdf -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/강의자료/03. Spring Boot Validation 모범사례/03. Spring Boot Validation 모범사례.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/강의자료/03. Spring Boot Validation 모범사례/03. Spring Boot Validation 모범사례.pdf -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/강의자료/04. Spring Boot Exception 처리/04. Spring Boot Exception 처리.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/강의자료/04. Spring Boot Exception 처리/04. Spring Boot Exception 처리.pdf -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/강의자료/05. Filter 와 Interceptor의 활용/05. Filter 와 Interceptor의 활용.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/강의자료/05. Filter 와 Interceptor의 활용/05. Filter 와 Interceptor의 활용.pdf -------------------------------------------------------------------------------- /06. 스프링의 기능을 활용해보자/강의자료/06. 비동기 처리 하기/06. 비동기 처리 하기.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/06. 스프링의 기능을 활용해보자/강의자료/06. 비동기 처리 하기/06. 비동기 처리 하기.pdf -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-web' 23 | compileOnly 'org.projectlombok:lombok' 24 | annotationProcessor 'org.projectlombok:lombok' 25 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 26 | } 27 | 28 | test { 29 | useJUnitPlatform() 30 | } 31 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/07. Server to Server 간의 연동/sourceCode/rest-template/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rest-template' 2 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/src/main/java/com/example/resttemplate/RestTemplateApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.resttemplate; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RestTemplateApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RestTemplateApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/src/main/java/com/example/resttemplate/controller/UserApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.resttemplate.controller; 2 | 3 | import com.example.resttemplate.service.UserService; 4 | import lombok.RequiredArgsConstructor; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | 8 | @RestController 9 | @RequestMapping("/api/user") 10 | @RequiredArgsConstructor 11 | public class UserApiController { 12 | 13 | private final UserService userService; 14 | 15 | @GetMapping("") 16 | public void get(){ 17 | userService.naver(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/src/main/java/com/example/resttemplate/dto/Car.java: -------------------------------------------------------------------------------- 1 | package com.example.resttemplate.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class Car { 11 | 12 | private String name; 13 | private String number; 14 | } 15 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/src/main/java/com/example/resttemplate/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.resttemplate.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class User { 13 | 14 | private String name; 15 | private int age; 16 | private List carList; 17 | } 18 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/rest-template/src/test/java/com/example/resttemplate/RestTemplateApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.resttemplate; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class RestTemplateApplicationTests { 8 | @Test 9 | public void contextLoads() { 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-web' 23 | compileOnly 'org.projectlombok:lombok' 24 | annotationProcessor 'org.projectlombok:lombok' 25 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 26 | } 27 | 28 | test { 29 | useJUnitPlatform() 30 | } 31 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/07. Server to Server 간의 연동/sourceCode/server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'server' 2 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/src/main/java/com/example/server/ServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ServerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/src/main/java/com/example/server/controller/UserApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.server.controller; 2 | 3 | import com.example.server.dto.Car; 4 | import com.example.server.dto.User; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.util.Arrays; 9 | 10 | @Slf4j 11 | @RestController 12 | @RequestMapping("/api/user") 13 | public class UserApiController { 14 | 15 | @GetMapping("") 16 | public User get(@RequestParam String name, @RequestParam int age){ 17 | User user = new User(); 18 | user.setName(name); 19 | user.setAge(age); 20 | return user; 21 | } 22 | 23 | @GetMapping("/user") 24 | public User user(){ 25 | User user = new User(); 26 | user.setName("홍길동"); 27 | user.setAge(10); 28 | 29 | user.setCarList(Arrays.asList( 30 | new Car("K5","11가 1111"), 31 | new Car("A4","22나 2222"), 32 | new Car("BMW","33가 3333") 33 | )); 34 | 35 | return user; 36 | } 37 | 38 | @PostMapping("") 39 | public User post(@RequestBody User user){ 40 | return user; 41 | } 42 | 43 | @PostMapping("header") 44 | public User header(@RequestHeader(value = "x-authorization") String header, @RequestBody User user){ 45 | log.info("header : {}",header); 46 | log.info("body : {}", user); 47 | return user; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/src/main/java/com/example/server/dto/Car.java: -------------------------------------------------------------------------------- 1 | package com.example.server.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class Car { 11 | 12 | private String name; 13 | private String number; 14 | } 15 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/src/main/java/com/example/server/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.server.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class User { 13 | 14 | private String name; 15 | private int age; 16 | private List carList; 17 | } 18 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/sourceCode/server/src/test/java/com/example/server/ServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.server; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ServerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07. Server to Server 간의 연동/강의자료/07. Server to Server 통신.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/07. Server to Server 간의 연동/강의자료/07. Server to Server 통신.pdf -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.5' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | id 'jacoco' 6 | } 7 | 8 | group = 'com.example' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '11' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | jacoco { 17 | toolVersion = "0.8.5" 18 | reportsDir = file("$buildDir/customJacocoReportDir") 19 | } 20 | 21 | jacocoTestReport { 22 | reports { 23 | xml.enabled false 24 | csv.enabled false 25 | html.destination file("${buildDir}/jacocoHtml") 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation 'org.springframework.boot:spring-boot-starter-web' 31 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 32 | compileOnly 'org.projectlombok:lombok' 33 | annotationProcessor 'org.projectlombok:lombok' 34 | } 35 | 36 | test { 37 | useJUnitPlatform() 38 | } 39 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/08. JUnit/sourceCode/calculator/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'calculator' 2 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/CalculatorApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CalculatorApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CalculatorApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/controller/CalculatorApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator.controller; 2 | 3 | import com.example.calculator.dto.CalculatorReq; 4 | import com.example.calculator.dto.CalculatorRes; 5 | import com.example.calculator.service.DollarCalculator; 6 | import com.example.calculator.service.ICalculator; 7 | import com.example.calculator.service.MarketServer; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.web.bind.annotation.*; 11 | import org.yaml.snakeyaml.error.Mark; 12 | 13 | @RestController 14 | @RequestMapping("/api/calculator") 15 | public class CalculatorApiController { 16 | 17 | private final ICalculator iCalculator; 18 | 19 | public CalculatorApiController(DollarCalculator dollarCalculator) { 20 | this.iCalculator = dollarCalculator; 21 | } 22 | 23 | @GetMapping("/hello") 24 | public String hello(){ 25 | return "hello"; 26 | } 27 | 28 | @GetMapping("/sum") 29 | public int get(CalculatorReq calculatorReq){ 30 | int result = iCalculator.sum(calculatorReq.getX(), calculatorReq.getY()); 31 | return result; 32 | } 33 | 34 | @PostMapping("/sum") 35 | public CalculatorRes post(@RequestBody CalculatorReq calculatorReq){ 36 | CalculatorRes res = new CalculatorRes(); 37 | var sum = iCalculator.sum(calculatorReq.getX(), calculatorReq.getY()); 38 | res.setResult(sum); 39 | 40 | var body = new CalculatorRes.Result(); 41 | body.setResponseResult(sum); 42 | 43 | res.setBody(body); 44 | return res; 45 | } 46 | 47 | /* @RequestMapping("/sum") 48 | public int mapping(@RequestBody CalculatorReq calculatorReq){ 49 | return dollarCalculator.sum(calculatorReq.getX(), calculatorReq.getY()); 50 | }*/ 51 | } 52 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/dto/CalculatorReq.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator.dto; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CalculatorReq { 7 | private int x; 8 | private int y; 9 | } 10 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/dto/CalculatorRes.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator.dto; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CalculatorRes { 7 | private int result; 8 | private Result body; 9 | 10 | 11 | @Data 12 | public static class Result{ 13 | int responseResult; 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/service/DollarCalculator.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class DollarCalculator implements ICalculator { 7 | private int market = 100; 8 | private final MarketServer marketServer; 9 | 10 | public DollarCalculator(MarketServer marketServer) { 11 | this.marketServer = marketServer; 12 | } 13 | 14 | @Override 15 | public int sum(int x, int y) { 16 | x *= marketServer.price(); 17 | y *= marketServer.price(); 18 | return x + y; 19 | } 20 | 21 | @Override 22 | public int minus(int x, int y) { 23 | x *= marketServer.price(); 24 | y *= marketServer.price(); 25 | return x - y; 26 | } 27 | 28 | @Override 29 | public int multiply(int x, int y) { 30 | x *= marketServer.price(); 31 | y *= marketServer.price(); 32 | return x * y; 33 | } 34 | 35 | @Override 36 | public int division(int x, int y) { 37 | x *= marketServer.price(); 38 | y *= marketServer.price(); 39 | return x / y; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/service/ICalculator.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator.service; 2 | 3 | public interface ICalculator { 4 | int sum(int x, int y); 5 | int minus(int x, int y); 6 | int multiply(int x, int y); 7 | int division(int x, int y); 8 | } 9 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/java/com/example/calculator/service/MarketServer.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator.service; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class MarketServer { 8 | 9 | public int price(){ 10 | return 100; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 -------------------------------------------------------------------------------- /08. JUnit/sourceCode/calculator/src/test/java/com/example/calculator/AbstractCalculatorReqApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.calculator; 2 | 3 | import com.example.calculator.service.DollarCalculator; 4 | import com.example.calculator.service.MarketServer; 5 | import org.junit.jupiter.api.Test; 6 | import org.mockito.Mock; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import static org.mockito.BDDMockito.given; 11 | 12 | 13 | @SpringBootTest 14 | class AbstractCalculatorReqApplicationTests { 15 | 16 | @Autowired 17 | private DollarCalculator dollarCalculator; 18 | 19 | @Mock 20 | private MarketServer marketServer; 21 | 22 | @Test 23 | void contextLoads() { 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../:\java-calculator\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | group 'org.example' 6 | version '1.0-SNAPSHOT' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | //testCompile group: 'junit', name: 'junit', version: '4.12' 14 | testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.7.1' 15 | testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.9.0' 16 | testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.9.0' 17 | } 18 | 19 | test { 20 | useJUnitPlatform() 21 | } 22 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/reports/tests/test/classes/Test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Test results - Class Test 7 | 8 | 9 | 10 | 11 | 12 |
13 |

Class Test

14 | 17 |
18 | 19 | 20 | 52 | 58 | 59 |
21 |
22 | 23 | 24 | 30 | 36 | 42 | 48 | 49 |
25 |
26 |
1
27 |

tests

28 |
29 |
31 |
32 |
0
33 |

failures

34 |
35 |
37 |
38 |
0
39 |

ignored

40 |
41 |
43 |
44 |
0.358s
45 |

duration

46 |
47 |
50 |
51 |
53 |
54 |
100%
55 |

successful

56 |
57 |
60 |
61 |
62 | 67 |
68 |

Tests

69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
TestDurationResult
mock()0.358spassed
83 |
84 |
85 | 94 |
95 | 96 | 97 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/reports/tests/test/css/style.css: -------------------------------------------------------------------------------- 1 | 2 | #summary { 3 | margin-top: 30px; 4 | margin-bottom: 40px; 5 | } 6 | 7 | #summary table { 8 | border-collapse: collapse; 9 | } 10 | 11 | #summary td { 12 | vertical-align: top; 13 | } 14 | 15 | .breadcrumbs, .breadcrumbs a { 16 | color: #606060; 17 | } 18 | 19 | .infoBox { 20 | width: 110px; 21 | padding-top: 15px; 22 | padding-bottom: 15px; 23 | text-align: center; 24 | } 25 | 26 | .infoBox p { 27 | margin: 0; 28 | } 29 | 30 | .counter, .percent { 31 | font-size: 120%; 32 | font-weight: bold; 33 | margin-bottom: 8px; 34 | } 35 | 36 | #duration { 37 | width: 125px; 38 | } 39 | 40 | #successRate, .summaryGroup { 41 | border: solid 2px #d0d0d0; 42 | -moz-border-radius: 10px; 43 | border-radius: 10px; 44 | } 45 | 46 | #successRate { 47 | width: 140px; 48 | margin-left: 35px; 49 | } 50 | 51 | #successRate .percent { 52 | font-size: 180%; 53 | } 54 | 55 | .success, .success a { 56 | color: #008000; 57 | } 58 | 59 | div.success, #successRate.success { 60 | background-color: #bbd9bb; 61 | border-color: #008000; 62 | } 63 | 64 | .failures, .failures a { 65 | color: #b60808; 66 | } 67 | 68 | .skipped, .skipped a { 69 | color: #c09853; 70 | } 71 | 72 | div.failures, #successRate.failures { 73 | background-color: #ecdada; 74 | border-color: #b60808; 75 | } 76 | 77 | ul.linkList { 78 | padding-left: 0; 79 | } 80 | 81 | ul.linkList li { 82 | list-style: none; 83 | margin-bottom: 5px; 84 | } 85 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/reports/tests/test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Test results - Test Summary 7 | 8 | 9 | 10 | 11 | 12 |
13 |

Test Summary

14 |
15 | 16 | 17 | 49 | 55 | 56 |
18 |
19 | 20 | 21 | 27 | 33 | 39 | 45 | 46 |
22 |
23 |
1
24 |

tests

25 |
26 |
28 |
29 |
0
30 |

failures

31 |
32 |
34 |
35 |
0
36 |

ignored

37 |
38 |
40 |
41 |
0.358s
42 |

duration

43 |
44 |
47 |
48 |
50 |
51 |
100%
52 |

successful

53 |
54 |
57 |
58 |
59 | 67 |
68 |

Packages

69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
PackageTestsFailuresIgnoredDurationSuccess rate
83 | default-package 84 | 1000.358s100%
93 |
94 |
95 |

Classes

96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 |
ClassTestsFailuresIgnoredDurationSuccess rate
110 | Test 111 | 1000.358s100%
120 |
121 |
122 | 131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/reports/tests/test/packages/default-package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Test results - Default package 7 | 8 | 9 | 10 | 11 | 12 |
13 |

Default package

14 | 16 |
17 | 18 | 19 | 51 | 57 | 58 |
20 |
21 | 22 | 23 | 29 | 35 | 41 | 47 | 48 |
24 |
25 |
1
26 |

tests

27 |
28 |
30 |
31 |
0
32 |

failures

33 |
34 |
36 |
37 |
0
38 |

ignored

39 |
40 |
42 |
43 |
0.358s
44 |

duration

45 |
46 |
49 |
50 |
52 |
53 |
100%
54 |

successful

55 |
56 |
59 |
60 |
61 | 66 |
67 |

Classes

68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
ClassTestsFailuresIgnoredDurationSuccess rate
81 | Test 82 | 1000.358s100%
90 |
91 |
92 | 101 |
102 | 103 | 104 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/test-results/test/binary/output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/08. JUnit/sourceCode/java-calculator/build/test-results/test/binary/output.bin -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/test-results/test/binary/output.bin.idx: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/build/test-results/test/binary/results.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/08. JUnit/sourceCode/java-calculator/build/test-results/test/binary/results.bin -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/08. JUnit/sourceCode/java-calculator/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'java-calculator' 2 | 3 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/src/main/java/Calculator.java: -------------------------------------------------------------------------------- 1 | public class Calculator { 2 | private ICalculator iCalculator; 3 | 4 | public Calculator(ICalculator iCalculator) { 5 | this.iCalculator = iCalculator; 6 | } 7 | 8 | public int sum(int x, int y) { 9 | return iCalculator.sum(x, y); 10 | } 11 | 12 | public int minus(int x, int y) { 13 | return iCalculator.minus(x, y); 14 | } 15 | 16 | public int multiply(int x, int y) { 17 | return iCalculator.multiply(x, y); 18 | } 19 | 20 | public int division(int x, int y) { 21 | return iCalculator.division(x, y); 22 | } 23 | } -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/src/main/java/DollarCalculator.java: -------------------------------------------------------------------------------- 1 | public class DollarCalculator implements ICalculator{ 2 | private int market = 0; 3 | private MarketServer marketServer; 4 | 5 | public DollarCalculator(MarketServer marketServer){ 6 | this.marketServer = marketServer; 7 | } 8 | 9 | public void init(){ 10 | this.market = marketServer.price(); 11 | } 12 | 13 | @Override 14 | public int sum(int x, int y) { 15 | x *= market; 16 | y *= market; 17 | return x + y ; 18 | } 19 | 20 | @Override 21 | public int minus(int x, int y) { 22 | x *= market; 23 | y *= market; 24 | return x - y; 25 | } 26 | 27 | @Override 28 | public int multiply(int x, int y) { 29 | x *= market; 30 | y *= market; 31 | return x * y; 32 | } 33 | 34 | @Override 35 | public int division(int x, int y) { 36 | x *= market; 37 | y *= market; 38 | return x / y; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/src/main/java/ICalculator.java: -------------------------------------------------------------------------------- 1 | public interface ICalculator { 2 | int sum(int x, int y); 3 | int minus(int x, int y); 4 | int multiply(int x, int y); 5 | int division(int x, int y); 6 | } 7 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/src/main/java/MarketServer.java: -------------------------------------------------------------------------------- 1 | public class MarketServer { 2 | 3 | public int price(){ 4 | return 100; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /08. JUnit/sourceCode/java-calculator/src/test/java/Test.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.Assertions; 2 | import org.junit.jupiter.api.BeforeEach; 3 | import org.junit.jupiter.api.extension.ExtendWith; 4 | import org.mockito.Mock; 5 | import org.mockito.Mockito; 6 | import org.mockito.junit.jupiter.MockitoExtension; 7 | 8 | @ExtendWith(MockitoExtension.class) 9 | public class Test { 10 | @Mock 11 | public MarketServer marketServer; 12 | 13 | @BeforeEach 14 | public void init(){ 15 | Mockito.lenient().when(marketServer.price()).thenReturn(200); 16 | } 17 | 18 | @org.junit.jupiter.api.Test 19 | public void hello(){ 20 | System.out.println("hello"); 21 | } 22 | 23 | @org.junit.jupiter.api.Test 24 | public void dollar(){ 25 | DollarCalculator dollarCalculator = new DollarCalculator(null); 26 | Calculator calculator = new Calculator(dollarCalculator); 27 | int sum = calculator.sum(100, 100); 28 | Assertions.assertEquals(20000, sum); 29 | } 30 | 31 | @org.junit.jupiter.api.Test 32 | public void mock(){ 33 | DollarCalculator dollarCalculator = new DollarCalculator(marketServer); 34 | dollarCalculator.init(); 35 | 36 | Calculator calculator = new Calculator(dollarCalculator); 37 | int sum = calculator.sum(100, 100); 38 | Assertions.assertEquals(40000, sum); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /08. JUnit/강의자료/08. Junit란.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/08. JUnit/강의자료/08. Junit란.pdf -------------------------------------------------------------------------------- /09. swagger/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.5' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-web' 23 | compileOnly 'org.projectlombok:lombok' 24 | annotationProcessor 'org.projectlombok:lombok' 25 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 26 | 27 | implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' 28 | } 29 | 30 | test { 31 | useJUnitPlatform() 32 | } 33 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/09. swagger/sourceCode/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /09. swagger/sourceCode/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'swagger' 2 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/src/main/java/com/example/swagger/SwaggerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.swagger; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 6 | 7 | @SpringBootApplication 8 | public class SwaggerApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(SwaggerApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/src/main/java/com/example/swagger/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.swagger.controller; 2 | 3 | import com.example.swagger.dto.UserRequest; 4 | import com.example.swagger.dto.UserResponse; 5 | import io.swagger.annotations.*; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | @Api(tags = {"REST API CONTROLLER"}) 9 | @RestController 10 | @RequestMapping("/api") 11 | public class ApiController { 12 | 13 | @ApiOperation(value = "hello method", notes = "기본적인 인사 GET API") 14 | /* @ApiImplicitParams({ 15 | @ApiImplicitParam(name = "name", value = "사용자 이름", required = true, dataType = "string", paramType = "path"), 16 | @ApiImplicitParam(name = "age", value = "사용자 나이", required = true, dataType = "int", paramType = "query") 17 | })*/ 18 | @GetMapping("/hello/{name}") 19 | public String hello( 20 | @ApiParam(value = "사용자 이름") 21 | @PathVariable String name, 22 | 23 | @ApiParam(value = "사용자 나이") 24 | @RequestParam int age){ 25 | return "hello"; 26 | } 27 | 28 | @GetMapping("/user") 29 | public UserResponse user(UserRequest userRequest){ 30 | return new UserResponse(userRequest.getName(), userRequest.getAge()); 31 | } 32 | 33 | @PostMapping("/user") 34 | @ApiResponse(code = 404, message = "not found") 35 | public UserResponse post(@RequestBody UserRequest userRequest){ 36 | return new UserResponse(userRequest.getName(), userRequest.getAge()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/src/main/java/com/example/swagger/dto/UserRequest.java: -------------------------------------------------------------------------------- 1 | package com.example.swagger.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import io.swagger.annotations.ApiParam; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Data 13 | public class UserRequest { 14 | 15 | @ApiModelProperty(value = "사용자 이름", example = "steve") 16 | private String name; 17 | 18 | 19 | @ApiModelProperty(value = "사용자 나이", example = "10") 20 | private int age; 21 | } 22 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/src/main/java/com/example/swagger/dto/UserResponse.java: -------------------------------------------------------------------------------- 1 | package com.example.swagger.dto; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | import io.swagger.annotations.ApiParam; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Data 12 | public class UserResponse { 13 | 14 | @ApiModelProperty(value = "사용자 이름", example = "steve") 15 | private String name; 16 | 17 | 18 | @ApiModelProperty(value = "사용자 나이", example = "10") 19 | private int age; 20 | } 21 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /09. swagger/sourceCode/src/test/java/com/example/swagger/SwaggerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.swagger; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SwaggerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09. swagger/강의자료/09. Swagger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/09. swagger/강의자료/09. Swagger.pdf -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.5' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 23 | implementation 'org.springframework.boot:spring-boot-starter-web' 24 | compileOnly 'org.projectlombok:lombok' 25 | annotationProcessor 'org.projectlombok:lombok' 26 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 27 | // https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter 28 | implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' 29 | } 30 | 31 | test { 32 | useJUnitPlatform() 33 | } 34 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'restaurant' 2 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/RestaurantApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RestaurantApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RestaurantApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.controller; 2 | 3 | import com.example.restaurant.wishlist.dto.WishListDto; 4 | import com.example.restaurant.wishlist.service.WishListService; 5 | import lombok.RequiredArgsConstructor; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.List; 11 | 12 | @Slf4j 13 | @RestController 14 | @RequestMapping("/api/restaurant") 15 | @RequiredArgsConstructor 16 | public class ApiController { 17 | 18 | private final WishListService wishListService; 19 | 20 | @GetMapping("/search") 21 | public WishListDto search(@RequestParam String query){ 22 | return wishListService.search(query); 23 | } 24 | 25 | @PostMapping("") 26 | public WishListDto add(@RequestBody WishListDto wishListDto){ 27 | log.info("{}", wishListDto); 28 | return wishListService.add(wishListDto); 29 | } 30 | 31 | @GetMapping("/all") 32 | public List findAll(){ 33 | return wishListService.findAll(); 34 | } 35 | 36 | @DeleteMapping("/{index}") 37 | public void delete(@PathVariable int index){ 38 | wishListService.delete(index); 39 | } 40 | 41 | @PostMapping("/{index}") 42 | public void addVisit(@PathVariable int index){ 43 | wishListService.addVisit(index); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/controller/PageController.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.servlet.ModelAndView; 7 | 8 | @Controller 9 | @RequestMapping("/pages") 10 | public class PageController { 11 | 12 | @GetMapping("/main") 13 | public ModelAndView main(){ 14 | return new ModelAndView("aaaa/main"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/db/MemoryDbEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.db; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class MemoryDbEntity { 11 | protected Integer index; 12 | } 13 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/db/MemoryDbRepositoryAbstract.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.db; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | abstract public class MemoryDbRepositoryAbstract implements MemoryDbRepositoryIfs { 8 | 9 | private final List db = new ArrayList<>(); 10 | private int index = 0; 11 | 12 | @Override 13 | public Optional findById(int index) { 14 | return db.stream().filter(it -> it.getIndex() == index).findFirst(); 15 | } 16 | 17 | @Override 18 | public T save(T entity) { 19 | var optionalEntity = db.stream().filter(it -> it.getIndex() == entity.getIndex()).findFirst(); 20 | 21 | if(optionalEntity.isEmpty()){ 22 | // db 에 데이터가 없는 경우 23 | index++; 24 | entity.setIndex(index); 25 | db.add(entity); 26 | return entity; 27 | 28 | }else{ 29 | // db 에 이미 데이터가 있는 경우 30 | var preIndex = optionalEntity.get().getIndex(); 31 | entity.setIndex(preIndex); 32 | 33 | deleteById(preIndex); 34 | db.add(entity); 35 | return entity; 36 | } 37 | } 38 | 39 | @Override 40 | public void deleteById(int index) { 41 | var optionalEntity = db.stream().filter(it -> it.getIndex() == index).findFirst(); 42 | if(optionalEntity.isPresent()){ 43 | db.remove(optionalEntity.get()); 44 | } 45 | } 46 | 47 | @Override 48 | public List findAll() { 49 | return db; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/db/MemoryDbRepositoryIfs.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.db; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public interface MemoryDbRepositoryIfs { 7 | Optional findById(int index); 8 | T save(T entity); 9 | void deleteById(int index); 10 | List findAll(); 11 | } 12 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/naver/NaverClient.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.naver; 2 | 3 | import com.example.restaurant.naver.dto.SearchImageReq; 4 | import com.example.restaurant.naver.dto.SearchImageRes; 5 | import com.example.restaurant.naver.dto.SearchLocalReq; 6 | import com.example.restaurant.naver.dto.SearchLocalRes; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.core.ParameterizedTypeReference; 9 | import org.springframework.http.HttpEntity; 10 | import org.springframework.http.HttpHeaders; 11 | import org.springframework.http.HttpMethod; 12 | import org.springframework.http.MediaType; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.web.client.RestTemplate; 15 | import org.springframework.web.util.UriComponentsBuilder; 16 | 17 | @Component 18 | public class NaverClient { 19 | 20 | @Value("${naver.client.id}") 21 | private String naverClientId; 22 | 23 | @Value("${naver.client.secret}") 24 | private String naverClientSecret; 25 | 26 | @Value("${naver.url.search.local}") 27 | private String naverLocalSearchUrl; 28 | 29 | @Value("${naver.url.search.image}") 30 | private String naverImageSearchUrl; 31 | 32 | public SearchLocalRes searchLocal(SearchLocalReq searchLocalReq){ 33 | var uri = UriComponentsBuilder.fromUriString(naverLocalSearchUrl) 34 | .queryParams(searchLocalReq.toMultiValueMap()) 35 | .build() 36 | .encode() 37 | .toUri(); 38 | 39 | var headers = new HttpHeaders(); 40 | headers.set("X-Naver-Client-Id", naverClientId); 41 | headers.set("X-Naver-Client-Secret", naverClientSecret); 42 | headers.setContentType(MediaType.APPLICATION_JSON); 43 | 44 | var httpEntity = new HttpEntity<>(headers); 45 | var responseType = new ParameterizedTypeReference(){}; 46 | 47 | 48 | var responseEntity = new RestTemplate().exchange( 49 | uri, 50 | HttpMethod.GET, 51 | httpEntity, 52 | responseType 53 | ); 54 | 55 | return responseEntity.getBody(); 56 | } 57 | 58 | 59 | public SearchImageRes searchImage(SearchImageReq searchImageReq){ 60 | var uri = UriComponentsBuilder.fromUriString(naverImageSearchUrl) 61 | .queryParams(searchImageReq.toMultiValueMap()) 62 | .build() 63 | .encode() 64 | .toUri(); 65 | 66 | var headers = new HttpHeaders(); 67 | headers.set("X-Naver-Client-Id", naverClientId); 68 | headers.set("X-Naver-Client-Secret", naverClientSecret); 69 | headers.setContentType(MediaType.APPLICATION_JSON); 70 | 71 | var httpEntity = new HttpEntity<>(headers); 72 | var responseType = new ParameterizedTypeReference(){}; 73 | 74 | 75 | var responseEntity = new RestTemplate().exchange( 76 | uri, 77 | HttpMethod.GET, 78 | httpEntity, 79 | responseType 80 | ); 81 | 82 | return responseEntity.getBody(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/naver/dto/SearchImageReq.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.naver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.springframework.util.LinkedMultiValueMap; 7 | import org.springframework.util.MultiValueMap; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class SearchImageReq { 13 | 14 | private String query = ""; 15 | 16 | private int display = 1; 17 | 18 | private int start = 1; 19 | 20 | private String sort = "sim"; 21 | 22 | private String filter = "all"; 23 | 24 | public MultiValueMap toMultiValueMap(){ 25 | var map = new LinkedMultiValueMap(); 26 | 27 | map.add("query",query); 28 | map.add("display",String.valueOf(display)); 29 | map.add("start", String.valueOf(start)); 30 | map.add("sort",sort); 31 | map.add("filter",filter); 32 | return map; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/naver/dto/SearchImageRes.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.naver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class SearchImageRes { 13 | 14 | private String lastBuildDate; 15 | private int total; 16 | private int start; 17 | private int display; 18 | private List items; 19 | 20 | 21 | 22 | @Data 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | public static class SearchImageItem { 26 | private String title; 27 | private String link; 28 | private String thumbnail; 29 | private String sizeheight; 30 | private String sizewidth; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/naver/dto/SearchLocalReq.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.naver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.springframework.util.LinkedMultiValueMap; 7 | import org.springframework.util.MultiValueMap; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class SearchLocalReq { 13 | 14 | private String query = ""; 15 | 16 | private int display = 1; 17 | 18 | private int start = 1; 19 | 20 | private String sort = "random"; 21 | 22 | public MultiValueMap toMultiValueMap(){ 23 | var map = new LinkedMultiValueMap(); 24 | 25 | map.add("query",query); 26 | map.add("display",String.valueOf(display)); 27 | map.add("start", String.valueOf(start)); 28 | map.add("sort",sort); 29 | return map; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/naver/dto/SearchLocalRes.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.naver.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class SearchLocalRes { 13 | 14 | private String lastBuildDate; 15 | private int total; 16 | private int start; 17 | private int display; 18 | private List items; 19 | 20 | 21 | 22 | @Data 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | public static class SearchLocalItem { 26 | private String title; 27 | private String link; 28 | private String description; 29 | private String category; 30 | private String telephone; 31 | private String address; 32 | private String roadAddress; 33 | private int mapx; 34 | private int mapy; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/wishlist/dto/WishListDto.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.wishlist.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDateTime; 8 | 9 | @NoArgsConstructor 10 | @AllArgsConstructor 11 | @Data 12 | public class WishListDto { 13 | private Integer index; 14 | private String title; // 음식명, 장소명 15 | private String category; // 카테고리 16 | private String address; // 주소 17 | private String roadAddress; // 도로명 18 | private String homePageLink; // 홈페이지 주소 19 | private String imageLink; // 음식, 가게 이미지 주소 20 | private boolean isVisit; // 방문여부 21 | private int visitCount; // 방문 카운트 22 | private LocalDateTime lastVisitDate; // 마지막 방문일자 23 | 24 | } 25 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/wishlist/entity/WishListEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.wishlist.entity; 2 | 3 | import com.example.restaurant.db.MemoryDbEntity; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Data 13 | public class WishListEntity extends MemoryDbEntity { 14 | 15 | private String title; // 음식명, 장소명 16 | private String category; // 카테고리 17 | private String address; // 주소 18 | private String roadAddress; // 도로명 19 | private String homePageLink; // 홈페이지 주소 20 | private String imageLink; // 음식, 가게 이미지 주소 21 | private boolean isVisit; // 방문여부 22 | private int visitCount; // 방문 카운트 23 | private LocalDateTime lastVisitDate; // 마지막 방문일자 24 | } 25 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/java/com/example/restaurant/wishlist/repository/WishListRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.wishlist.repository; 2 | 3 | import com.example.restaurant.db.MemoryDbRepositoryAbstract; 4 | import com.example.restaurant.wishlist.entity.WishListEntity; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public class WishListRepository extends MemoryDbRepositoryAbstract { 9 | } 10 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | naver: 2 | url: 3 | search: 4 | local: https://openapi.naver.com/v1/search/local.json 5 | image: https://openapi.naver.com/v1/search/image 6 | client: 7 | id: Zi3o1uQftp59zuIqEAz4 8 | secret: iy6YKSWpLM -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/main/resources/static/js/main.js: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | 3 | // 검색 결과 vue object 4 | var search_result = new Vue({ 5 | el: '#search-result', 6 | data: { 7 | search_result : {} 8 | }, 9 | method: { 10 | wishButton: function (event) { 11 | console.log("add"); 12 | } 13 | } 14 | }); 15 | 16 | // 맛집 목록 vue object 17 | var wish_list = new Vue({ 18 | el: '#wish-list', 19 | data: { 20 | wish_list : {} 21 | }, 22 | methods: { 23 | addVisit: function (index) { 24 | $.ajax({ 25 | type: "POST" , 26 | async: true , 27 | url: `/api/restaurant/${index}`, 28 | timeout: 3000 29 | }); 30 | 31 | getWishList(); 32 | }, 33 | deleteWish: function (index) { 34 | $.ajax({ 35 | type: "DELETE" , 36 | async: true , 37 | url: `/api/restaurant/${index}`, 38 | timeout: 3000 39 | }); 40 | getWishList(); 41 | } 42 | } 43 | }); 44 | 45 | // search 46 | $("#searchButton").click(function () { 47 | const query = $("#searchBox").val(); 48 | $.get(`/api/restaurant/search?query=${query}`, function (response) { 49 | search_result.search_result = response; 50 | $('#search-result').attr('style','visible'); 51 | }); 52 | }); 53 | 54 | // Enter 55 | $("#searchBox").keydown(function(key) { 56 | if (key.keyCode === 13) { 57 | const query = $("#searchBox").val(); 58 | $.get(`/api/restaurant/search?query=${query}`, function (response) { 59 | search_result.search_result = response; 60 | $('#search-result').attr('style','visible'); 61 | }); 62 | } 63 | }); 64 | 65 | $("#wishButton").click(function () { 66 | $.ajax({ 67 | type: "POST" , 68 | async: true , 69 | url: "/api/restaurant", 70 | timeout: 3000, 71 | data: JSON.stringify(search_result.search_result), 72 | contentType: "application/json", 73 | error: function (request, status, error) { 74 | 75 | }, 76 | success: function (response, status, request) { 77 | getWishList(); 78 | } 79 | }); 80 | }); 81 | 82 | function getWishList(){ 83 | $.get(`/api/restaurant/all`, function (response) { 84 | wish_list.wish_list = response; 85 | }); 86 | } 87 | 88 | $(document).ready(function () { 89 | console.log("init") 90 | }); 91 | 92 | })(jQuery); 93 | 94 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/test/java/com/example/restaurant/RestaurantApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class RestaurantApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/test/java/com/example/restaurant/naver/NaverClientTest.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.naver; 2 | 3 | import com.example.restaurant.naver.dto.SearchImageReq; 4 | import com.example.restaurant.naver.dto.SearchLocalReq; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | @SpringBootTest 11 | public class NaverClientTest { 12 | 13 | @Autowired 14 | private NaverClient naverClient; 15 | 16 | @Test 17 | public void searchLocalTest(){ 18 | 19 | var search = new SearchLocalReq(); 20 | search.setQuery("갈비집"); 21 | 22 | var result = naverClient.searchLocal(search); 23 | 24 | System.out.println(result); 25 | Assertions.assertNotNull(result.getItems().stream().findFirst().get().getCategory()); 26 | } 27 | 28 | @Test 29 | public void searchImageTest(){ 30 | var search = new SearchImageReq(); 31 | search.setQuery("갈비집"); 32 | 33 | var result = naverClient.searchImage(search); 34 | System.out.println(result); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/test/java/com/example/restaurant/wishlist/repository/WishListRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.wishlist.repository; 2 | 3 | import com.example.restaurant.wishlist.entity.WishListEntity; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | @SpringBootTest 10 | public class WishListRepositoryTest { 11 | 12 | @Autowired 13 | private WishListRepository wishListRepository; 14 | 15 | private WishListEntity create(){ 16 | var wishList = new WishListEntity(); 17 | wishList.setTitle("title"); 18 | wishList.setCategory("category"); 19 | wishList.setAddress("address"); 20 | wishList.setRoadAddress("readAddress"); 21 | wishList.setHomePageLink(""); 22 | wishList.setImageLink(""); 23 | wishList.setVisit(false); 24 | wishList.setVisitCount(0); 25 | wishList.setLastVisitDate(null); 26 | 27 | return wishList; 28 | } 29 | 30 | @Test 31 | public void saveTest(){ 32 | var wishListEntity = create(); 33 | var expected = wishListRepository.save(wishListEntity); 34 | 35 | Assertions.assertNotNull(expected); 36 | Assertions.assertEquals(1, expected.getIndex()); 37 | } 38 | 39 | @Test 40 | public void updateTest(){ 41 | var wishListEntity = create(); 42 | var expected = wishListRepository.save(wishListEntity); 43 | 44 | expected.setTitle("update test"); 45 | var saveEntity = wishListRepository.save(expected); 46 | 47 | Assertions.assertEquals("update test", saveEntity.getTitle()); 48 | Assertions.assertEquals(1, wishListRepository.findAll().size()); 49 | } 50 | 51 | @Test 52 | public void findByIdTest(){ 53 | var wishListEntity = create(); 54 | wishListRepository.save(wishListEntity); 55 | 56 | var expected = wishListRepository.findById(1); 57 | 58 | Assertions.assertEquals(true, expected.isPresent()); 59 | Assertions.assertEquals(1, expected.get().getIndex()); 60 | } 61 | 62 | @Test 63 | public void deleteTest(){ 64 | var wishListEntity = create(); 65 | wishListRepository.save(wishListEntity); 66 | 67 | wishListRepository.deleteById(1); 68 | 69 | int count = wishListRepository.findAll().size(); 70 | 71 | Assertions.assertEquals(0, count); 72 | } 73 | 74 | @Test 75 | public void listAllTest(){ 76 | var wishListEntity1 = create(); 77 | wishListRepository.save(wishListEntity1); 78 | 79 | var wishListEntity2 = create(); 80 | wishListRepository.save(wishListEntity2); 81 | 82 | int count = wishListRepository.findAll().size(); 83 | Assertions.assertEquals(2, count); 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/test/java/com/example/restaurant/wishlist/service/WishListServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.example.restaurant.wishlist.service; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | public class WishListServiceTest { 10 | 11 | @Autowired 12 | private WishListService wishListService; 13 | 14 | @Test 15 | public void searchTest(){ 16 | var result = wishListService.search("갈비집"); 17 | System.out.println(result); 18 | Assertions.assertNotNull(result); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /10. 네이버 지역검색 API를 활용한 맛집 List 만들기/restaurant/src/test/resources/application.yaml: -------------------------------------------------------------------------------- 1 | naver: 2 | url: 3 | search: 4 | local: https://openapi.naver.com/v1/search/local.json 5 | image: https://openapi.naver.com/v1/search/image 6 | client: 7 | id: Zi3o1uQftp59zuIqEAz4 8 | secret: iy6YKSWpLM -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fastcampus-springboot-introduction 2 | 패스트 캠퍼스 스프링 부트 입문 3 | -------------------------------------------------------------------------------- /food-list.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-developer/fastcampus-springboot-introduction/7f1c7298ee8f08ea82ef0628a9fff644ece0f231/food-list.zip --------------------------------------------------------------------------------