[SpringBoot][Quiz] 출력을 테스트해 주세요.
SpringBoot 프로젝트
PojectName : FirstSpringBootQuiz
GroupId : kr.ac.andong
ArtifactId : FirstSpringBootQuiz
설치 dependencies {
SpringBootVersion --> 2.1.7.RELEASE
plugin --> java, eclipse, springframework.boot, Lombok, spring-boot-starter-test,
spring-boot-starter-web
}
/hello를 Test파일을 만들어 테스트해 주세요.
결과는 "안녕하세요"로 만들어 주시고
테스트가 통화할 수 있도록 만들어 봅니다.
만들어야 되는 파일
build.gradle
application.properties --> server.port = 7070
Application.java
HelloController.java
HelloControllerTest.java --> 내용만 업로드 해 주세요.
build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | buildscript{ ext{ springBootVersion = '2.1.7.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group 'kr.ac.andong' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile('org.springframework.boot:spring-boot-starter-web') compile('org.projectlombok:lombok') testCompile('org.springframework.boot:spring-boot-starter-test') testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' } | cs |
application.properties
1 | server.port = 7070 | cs |
Application.java
1 2 3 4 5 6 7 8 9 10 11 12 | package kr.ac.andong.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } | cs |
HelloController.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | package kr.ac.andong.springboot.web; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/") public String index(){ return "메인 페이지"; } @GetMapping("/hello") public String hello(){ return "안녕하세요"; } } | cs |
HelloControllerTest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | package kr.ac.andong.springboot.web; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringRunner.class) @WebMvcTest(controllers = HelloController.class) public class HelloControllerTest { @Autowired private MockMvc mvc; @Test public void hello_return() throws Exception { String hello="안녕하세요"; mvc.perform(get("/hello")) .andExpect(status().isOk()) .andExpect(content().string(hello)); } } | cs |
디자인패턴 교재 - Head First Design Pattern
44쪽 - 인터페이스
51쪽
60쪽
-> Strategy 패턴
gradle에
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('com.h2database:h2')
추가
객체지향은 모든 것을 객체로 표현할 수 있다.
스프링 부트와 AWS로 혼자 구현하는 웹 서비스 78쪽 JPA
sql 안 쓰고도 게시판에 글 삽입 가능
Jpa 책
자바 ORM 표준 JPA 프로그래밍
-> 스프링만 집중한다면 괜찮은 책
-> 스프링에서 JPA는 핵심
2021년 개발트렌드는 JPA
SI는 JPA 안 씀
MyBatis 사용
쿠팡, 카카오, 배민같은 곳은 JPA 사용
스타트 스프링 부트에서는 타임리프와 JPA 설명
스프링 부트와 AWS로 혼자 구현하는 웹 서비스
89쪽까지 함
com.jojoldu.book.springboot 디렉터리 아래에 domain.posts 디렉터리 추가
Posts.java, PostsRepository 인터페이스 추가
Posts.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | package com.jojoldu.book.springboot.domain.posts; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import javax.persistence.*; @Getter @NoArgsConstructor @Entity public class Posts { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(length = 500, nullable = false) private String title; @Column(columnDefinition = "TEXT", nullable = false) private String content; private String author; @Builder public Posts(String title, String content, String author) { this.title = title; this.content = content; this.author = author; } } | cs |
PostsRepository 인터페이스
1 2 3 4 5 6 7 | package com.jojoldu.book.springboot.domain.posts; import org.springframework.data.jpa.repository.JpaRepository; public interface PostsRepository extends JpaRepository<Posts, Long> { } | cs |
'Java' 카테고리의 다른 글
| 스마트팩토리 12주 56일차 java 8일차 (0) | 2021.07.15 |
|---|---|
| 스마트팩토리 11주 55일차 java 7일차 (0) | 2021.07.14 |
| 스마트팩토리 11주 53일차 java 5일차 (0) | 2021.07.12 |
| 스마트팩토리 11주 52일차 java 4일차 (0) | 2021.07.08 |
| 스마트팩토리 11주 51일차 java 3일차 (0) | 2021.07.08 |




최근댓글