본문 바로가기

전체 글400

[Spring] 2-3. API @ResponseBody 문자 반환 Controller @Controller public class HelloController { @GetMapping("hello-string") @ResponseBody public String helloString(@RequestParam("name") String name) { return "hello " + name; } } @ResponseBody를 사용하면 뷰 리졸버(viewResolver)를 사용하지 않음 대신 HTTP의 BODY에 문자 내용을 직접 반환(HTML BODY TAG가 아님) 실행 : http://localhost:8080/hello-string?name=spring!! @ResponseBody 객체 반환 Controller @Controlle.. 2023. 10. 31.
[Spring] 2-2. MVC와 템플릿 엔진 MVC : Model, View, Controller Controller @Controller public class HelloController { @GetMapping("hello-mvc") public String helloMvc(@RequestParam("name") String name, Model model) { model.addAttribute("name", name); return "hello-template"; } } View resources/templates/hello-template.html hello! empty 실행 : http://localhost:8080/hello-mvc?name=spring MVC, 템플릿 엔진 이미지 https://www.inflearn.com/cours.. 2023. 10. 31.
[Spring] 2-1. 정적 컨텐츠 스프링 부트 정적 컨텐츠 기능 https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-static-content resources/static/hello-static.html 정적 컨텐츠 입니다. 실행 : http://localhost:8080/hello-static.html 정적 컨텐츠 이미지 https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EC%9E%85%EB%AC%B8-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8 [무료] 스프링 입문 - 코드로 .. 2023. 10. 31.
[Spring] 1-4. 빌드하고 실행하기 빌드하고 실행하기(windows) 콘솔로 이동 → 명령 프롬프트(cmd)로 이동 ./gradlew → gradlew.bat 실행 cmd에서 gradlew.bat를 실행하려면 gradlew하고 엔터 gradlew build cd ./build/libs java -jar hello-spring-0.0.1-SNAPSHOT.jar http://localhost:8080 확인 윈도우에서 Git bash 터미널 사용하기 링크 : https://www.inflearn.com/questions/53961 https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EC%9E%85%EB%AC%B8-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A.. 2023. 10. 30.
[Spring] 1-3. View 환경설정 Welcome Page 만들기 resources/static/index.html Hello hello 스프링 부트가 제공하는 Welcome Page 기능 static/index.html 을 올려두면 Welcome page 기능을 제공한다. https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-welcome-page thymeleaf 템플릿 엔진 thymeleaf 공식 사이트 : https://www.thymeleaf.org/ 스프링 공식 튜토리얼 : https://spring.io/guides/gs/serving-web-content/ 스프링 부.. 2023. 10. 30.
[Spring] 1-2. 라이브러리 살펴보기 Gradle은 의존관계가 있는 라이브러리를 함께 다운로드한다. 스프링 부트 라이브러리 spring-boot-starter-web spring-boot-starter-tomcat : 톰캣(웹 서버) spring-webmvc : 스프링 웹 MVC spring-boot-starter-thymeleaf : 타임리프 템플릿 엔진(View) spring-boot-starter(공통) : 스프링 부트 + 스프링 코어 + 로깅 spring-boot spring-core spring-boot-starter-logging logback, slf4j 테스트 라이브러리 spring-boot-starter-test junit : 테스트 프레임워크 mockito : 목 라이브러리 assertj : 테스트 코드를 좀 더 편하게 작.. 2023. 10. 30.