diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index c76fd96f..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/README.md b/README.md deleted file mode 100644 index 6874dc8e..00000000 --- a/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# UMC-7th-Spring-Study -πŸ’» Git clone 및 Branch 생성 -λ…Έμ…˜μ˜ 1,2μ£Όμ°¨ μ„Έμ…˜μ—μ„œ κΉƒ κ΄€λ ¨ λ‚΄μš©μ„ μ°Έκ³ ν•΄μ£Όμ„Έμš” :) - -git init // μ €μž₯μ†Œ 생성 - -git remote -v https://github.com/HIUMC/UMC-7th-Spring-Study.git //μ €μž₯μ†Œ λ‚΄ 컴퓨터 <-> 원격 μ—°κ²° - -git pull origin main - -terminalμ—μ„œ μžμ‹ μ˜ branch둜 checkout을 ν•΄μ£Όμ„Έμš” - -git checkout origin [본인 github 아이디] //브랜치 κ°œλ… λͺ¨λ₯Έλ‹€λ©΄ ꡬ글링. μžμ‹ λ§Œμ˜ 곡간을 λ§Œλ“ λ‹€κ³  μƒκ°ν•˜μ‹œλ©΄ λ©λ‹ˆλ‹€. - -μž‘μ—…μ€ ν•΄λ‹Ή 본인 branchμ—μ„œλ§Œ μ§„ν–‰ν•΄μ£Όμ„Έμš” (❌main branch❌) - -git branch : ν˜„μž¬ branch 확인 - -μœ„μ˜ 방식이 μ–΄λ ΅λ‹€λ©΄ κΉƒ Clone ν•˜λŠ” 방법을 검색해보기 - - -### 🏑 μž‘μ—…κ³΅κ°„ 생성 -* UMC-7th-Spring-Study (ν”„λ‘œμ νŠΈ 루트 디렉토리) - * 본인 github 아이디λͺ…μ˜ 디렉토리 (본인 github μ•„μ΄λ””λ‘œ μ„€μ •ν•΄μ£Όμ„Έμš”!) - * λ…Έλ“œ μ†ŒμŠ€μ½”λ“œ or μ›Œν¬λΆ κ³΅λΆ€ν•˜λ©΄μ„œ 배운 것 λ“±λ“±... - - -| 본인 github 아이디λͺ…μ˜ 디렉토리뢀터 λ§Œλ“€κ³  μ‹œμž‘ν•˜μ‹œλ©΄ λ©λ‹ˆλ‹€! 😊 -``` -β”‚ -└─ UMC-7th-Spring-Study - β”‚ - └─ dlguszoo (dir) - β”‚ - β”œβ”€ 1μ£Όμ°¨ (dir) - | └─ README.md // ν•΄λ‹Ή κ°•μ˜ μ •λ¦¬ν•œ λ‚΄μš©μ΄ λ‹΄κΈ΄ 파일 - | - β”œβ”€ 2μ£Όμ°¨ (dir) - β”‚ β”œβ”€ README.md // ν•΄λ‹Ή κ°•μ˜ μ •λ¦¬ν•œ λ‚΄μš©μ΄ λ‹΄κΈ΄ 파일 - β”‚ └─ Mission - β”‚ - β”œβ”€ 3μ£Όμ°¨ (dir) - β”‚ └─ .. μ΄ν•˜ 동일 -``` - - -### πŸ’Ύ 쀑간 쀑간 commit ν•˜κΈ° -* 파트 λ³„λ‘œ μž‘μ—…μ„ λλƒˆκ±°λ‚˜ 더 μž‘μ€ λ‹¨μœ„λ‘œ μž‘μ—…μ„ 끝낼 λ•Œ λ§ˆλ‹€ commit을 ν•΄ μ£ΌλŠ” 게 μ’‹μ•„μš” -* ❗commit convention ❗️ - * **Feat**: μƒˆλ‘œμš΄ κΈ°λŠ₯ μΆ”κ°€ - * **Fix**: 버그 μˆ˜μ • - * **Docs**: λ¬Έμ„œ μˆ˜μ • - * **Style**: μ½”λ“œ ν¬λ§·νŒ…, μ„Έλ―Έμ½œλ‘  λˆ„λ½, μ½”λ“œ 변경이 μ—†λŠ” 경우 - * **Refactor**: μ½”λ“œ λ¦¬νŽ™ν† λ§ - * **Test**: ν…ŒμŠ€νŠΈ μ½”λ“œ, λ¦¬νŽ™ν† λ§ ν…ŒμŠ€νŠΈ μ½”λ“œ μΆ”κ°€ - * **Chore**: λΉŒλ“œ 업무 μˆ˜μ •, νŒ¨ν‚€μ§€ λ§€λ‹ˆμ € μˆ˜μ • - -* μ˜ˆμ‹œ: ```git commit -m "[Feat(본인 이름(λ‹‰λ„€μž„)): OO κΈ°λŠ₯ μΆ”κ°€]"``` - - -### ✍🏻 README.md 파일 μž‘μ„±ν•˜κΈ° - - -* ν•΄λ‹Ή μ£Όμ°¨ 책을 κ³΅λΆ€ν•˜λ©΄μ„œ μ•Œκ²Œ 된 λΆ€λΆ„, μ€‘μš”ν•˜λ‹€κ³  μƒκ°ν•œ 뢀뢄이 μžˆλ‹€λ©΄ 정리해 μ£Όμ„Έμš”! - * κ°œλ… 정립도, μš”μ•½λ„ λͺ¨λ‘ μ’‹μŠ΅λ‹ˆλ‹€! 😊 -* ν•΄λ‹Ή μ£Όμ°¨ κ°•μ˜λ₯Ό λ“€μœΌλ©΄μ„œ μƒˆλ‘­κ²Œ μ•Œκ²Œ 된 μ‚¬μ‹€μ΄λ‚˜ μΆ”κ°€μ μœΌλ‘œ 더 κ³΅λΆ€ν•œ 뢀뢄이 μžˆλ‹€λ©΄ 정리해 μ£Όμ„Έμš”! - * μš”μ•½λ„, λ³΅μŠ΅λ„ λͺ¨λ‘ μ’‹μŠ΅λ‹ˆλ‹€! 😊😊 - - -* .md νŒŒμΌμ€ mark down μ–Έμ–΄λ‘œ μž‘μ„±λœ νŒŒμΌμ„ λœ»ν•΄μš” - * [μ°Έκ³ ] https://gist.github.com/ihoneymon/652be052a0727ad59601#24-μ½”λ“œ - - -### πŸ™ŒπŸ» Github λ ˆν¬μ§€ν† λ¦¬μ— pushν•˜κΈ° - -* ν•΄λ‹Ή 주차의 κ°•μ˜λ₯Ό λ“£κ±°λ‚˜ μž‘μ—…μ„ λͺ¨λ‘ λλƒˆλ‹€λ©΄, ν”„λ‘œμ νŠΈ λ³€κ²½ 사항을 remote repository(github repository)에 push ν•©λ‹ˆλ‹€ - * ```git push origin [본인 github 아이디 브랜치 λͺ…]``` : git에 λ“±λ‘λ˜μ–΄ μžˆλŠ” origin(github repository)에 μžˆλŠ” μžμ‹ μ˜ branch둜 ν”„λ‘œμ νŠΈμ˜ λ³€κ²½ 사항을 λ°˜μ˜ν•©λ‹ˆλ‹€ -* pushλ₯Ό μ™„λ£Œν–ˆλ‹€λ©΄ μŠ€ν„°λ”” repositoryμ—μ„œ pull requestλ₯Ό μ§„ν–‰ν•©λ‹ˆλ‹€ - * 링크: https://github.com/HIUMC/UMC-7th-Spring-Study.git/pulls -* PR(Pull Request)μ‹œ λ©”μ„Έμ§€ 제λͺ©μ€ λ‹€μŒκ³Ό 같이 ```[이름/λ‹‰λ„€μž„] 1μ£Όμ°¨ μ •λ¦¬λ‚΄μš© 제좜.``` 라고 적은 ν›„ ```create pull request``` λ²„νŠΌμ„ λˆŒλŸ¬μ£Όμ„Έμš” -* PR : ```base: [master]``` <- ```compare: [본인 github 아이디]``` - - -### ⏰ 과제 제좜 마감 κΈ°ν•œ (기재 μ˜ˆμ •) diff --git a/ajwoong/.DS_Store b/ajwoong/.DS_Store deleted file mode 100644 index e4dd73b1..00000000 Binary files a/ajwoong/.DS_Store and /dev/null differ diff --git a/ajwoong/hello-spring/.DS_Store b/ajwoong/hello-spring/.DS_Store deleted file mode 100644 index 9c0c9ae4..00000000 Binary files a/ajwoong/hello-spring/.DS_Store and /dev/null differ diff --git a/ajwoong/hello-spring/hello-spring/.DS_Store b/ajwoong/hello-spring/hello-spring/.DS_Store deleted file mode 100644 index ad1ecd6b..00000000 Binary files a/ajwoong/hello-spring/hello-spring/.DS_Store and /dev/null differ diff --git a/ajwoong/hello-spring/hello-spring/sql/ddl.sql b/ajwoong/hello-spring/hello-spring/sql/ddl.sql deleted file mode 100644 index 92e7ca3e..00000000 --- a/ajwoong/hello-spring/hello-spring/sql/ddl.sql +++ /dev/null @@ -1,7 +0,0 @@ -drop table if exits member CASCADE; -create table member -( - id bigint generated by default as identity, - name varchar(255), - primary key(id) -) \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/.DS_Store b/ajwoong/hello-spring/hello-spring/src/.DS_Store deleted file mode 100644 index 5893ce8b..00000000 Binary files a/ajwoong/hello-spring/hello-spring/src/.DS_Store and /dev/null differ diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/HelloSpringApplication.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/HelloSpringApplication.java deleted file mode 100644 index 7e3d0b85..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/HelloSpringApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package hello.hello_spring; - -import hello.hello_spring.repository.MemberRepository; -import hello.hello_spring.repository.SpringDataJpaMemberRepository; -import hello.hello_spring.service.MemberService; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HelloSpringApplication { - - public static void main(String[] args) { - SpringApplication.run(HelloSpringApplication.class, args); - } - -} - diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/SpringConfig.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/SpringConfig.java deleted file mode 100644 index 3f1fb40a..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/SpringConfig.java +++ /dev/null @@ -1,72 +0,0 @@ -package hello.hello_spring; - -import hello.hello_spring.aop.TimeTraceAop; -import hello.hello_spring.domain.Member; -import hello.hello_spring.repository.*; -import hello.hello_spring.service.MemberService; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.sql.DataSource; -import java.util.List; -import java.util.Optional; - -@Configuration -public class SpringConfig { - - - /** - * Jdbc template μ‚¬μš© - * **/ - -// private final DataSource dataSource; -// -// @Autowired -// public SpringConfig(DataSource dataSource) { -// this.dataSource = dataSource; -// } - -/** - * Jpa μ‚¬μš© - * **/ -// @PersistenceContext -// private EntityManager em; -// -// @Autowired -// public SpringConfig(EntityManager em) { -// this.em = em; -// } - -/** - * Spring DATA JPA μ‚¬μš© - * **/ - - private final MemberRepository memberRepository; - - @Autowired - public SpringConfig(MemberRepository memberRepository) { - this.memberRepository = memberRepository; - } - - @Bean - public MemberService memberService(){ - return new MemberService(memberRepository); - } - -// @Bean -// public TimeTraceAop timeTraceAop(){ -// return new TimeTraceAop(); -// } - -// @Bean -// public MemberRepository memberRepository(){ -// //return new MemoryMemberRepository(); -// // return new JdbcMemberRepository(dataSource); -// //return new JdbcTemplateMemberRepository(dataSource); -// // return new JpaMemberRepository(em); -// -// } -} diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/aop/TimeTraceAop.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/aop/TimeTraceAop.java deleted file mode 100644 index 66e782b8..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/aop/TimeTraceAop.java +++ /dev/null @@ -1,25 +0,0 @@ -package hello.hello_spring.aop; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.stereotype.Component; - -@Aspect -@Component -public class TimeTraceAop { - - @Around("execution(* hello.hello_spring..*(..))") - public Object execute(ProceedingJoinPoint joinPoint) throws Throwable { - long start = System.currentTimeMillis(); - System.out.println("START: " + joinPoint.toString()); - try{ - return joinPoint.proceed(); - }finally { - long finish = System.currentTimeMillis(); - long timeMs = finish - start; - System.out.println("END: " + joinPoint.toString() + " " + timeMs + "ms"); - } - - } -} diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JdbcTemplateMemberRepository.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JdbcTemplateMemberRepository.java deleted file mode 100644 index 6fc7a90f..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JdbcTemplateMemberRepository.java +++ /dev/null @@ -1,122 +0,0 @@ -package hello.hello_spring.repository; -import hello.hello_spring.domain.Member; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -import org.springframework.jdbc.core.simple.SimpleJdbcInsert; -import javax.sql.DataSource; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -public class JdbcTemplateMemberRepository implements MemberRepository { - - private final JdbcTemplate jdbcTemplate; - public JdbcTemplateMemberRepository(DataSource dataSource) { - jdbcTemplate = new JdbcTemplate(dataSource); - } - - @Override - public Member save(Member member) { - SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(jdbcTemplate); - jdbcInsert.withTableName("member").usingGeneratedKeyColumns("id"); - Map parameters = new HashMap<>(); - parameters.put("name", member.getName()); - Number key = jdbcInsert.executeAndReturnKey(new - MapSqlParameterSource(parameters)); - member.setId(key.longValue()); - return member; - } - - @Override - public Optional findById(Long id) { - List result = jdbcTemplate.query("select * from member where id = ?", memberRowMapper(), id); - return result.stream().findAny(); - } - - @Override - public List findAll() { - return jdbcTemplate.query("select * from member", memberRowMapper()); - } - - @Override - public Optional findByName(String name) { - List result = jdbcTemplate.query("select * from member where name = ?", memberRowMapper(), name); - return result.stream().findAny(); - } - - private RowMapper memberRowMapper() { - return (rs, rowNum) -> { - Member member = new Member(); - member.setId(rs.getLong("id")); - member.setName(rs.getString("name")); - return member; - }; - } -} - -//package hello.hello_spring.repository; -// -//import hello.hello_spring.domain.Member; -//import org.springframework.jdbc.core.JdbcTemplate; -//import org.springframework.jdbc.core.RowMapper; -//import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -//import org.springframework.jdbc.core.simple.SimpleJdbcInsert; -// -//import javax.sql.DataSource; -//import javax.swing.text.html.Option; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -//import java.util.Optional; -// -//public class JdbcTemplateMemberRepository implements MemberRepository{ -// -// private final JdbcTemplate jdbcTemplate; -// -// public JdbcTemplateMemberRepository(DataSource dataSource){ -// this.jdbcTemplate = new JdbcTemplate(dataSource); -// } -// -// @Override -// public Member save(Member member) { -// SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(jdbcTemplate); -// jdbcInsert.withTableName("member").usingGeneratedKeyColumns("id"); -// Map parameters = new HashMap<>(); -// parameters.put("name", member.getName()); -// Number key = jdbcInsert.executeAndReturnKey(new -// MapSqlParameterSource(parameters)); -// member.setId(key.longValue()); -// return member; -// } -// -// @Override -// public Optional findById(Long id) { -// List result = jdbcTemplate.query("select * from member where id = ?", memberRowMapper(),id); -// return result.stream().findAny(); -// } -// -// @Override -// public Optional findByName(String name) { -// List result = jdbcTemplate.query("select * from member where name = ?", memberRowMapper(), name); -// return Optional.empty(); -// } -// -// @Override -// public List findAll() { -// return jdbcTemplate.query("select * from member", memberRowMapper()); -// } -// -// private RowMapper memberRowMapper(){ -// return (rs, rowNum) -> { -// Member member = new Member(); -// member.setId(rs.getLong("id")); -// member.setName(rs.getString("name")); -// return member; -// }; -// } -// -//} diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/MemberRepository.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/MemberRepository.java deleted file mode 100644 index 059e2921..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/MemberRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package hello.hello_spring.repository; - -import hello.hello_spring.domain.Member; - -import javax.swing.text.html.Option; -import java.util.List; -import java.util.Optional; - -public interface MemberRepository { - Member save(Member member); - Optional findById(Long id); - Optional findByName(String name); - List findAll(); -} - - diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/MemoryMemberRepository.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/MemoryMemberRepository.java deleted file mode 100644 index 11fa0fc2..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/MemoryMemberRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -package hello.hello_spring.repository; - -import hello.hello_spring.domain.Member; - -import java.util.*; - - -public class MemoryMemberRepository implements MemberRepository{ - - private static Map store = new HashMap<>(); - private static long sequence = 0L; - - @Override - public Member save(Member member) { - member.setId(++sequence); - store.put(member.getId(), member); - return member; - } - - @Override - public Optional findById(Long id) { - return Optional.ofNullable(store.get(id)); - } - - @Override - public Optional findByName(String name) { - return store.values().stream() - .filter(member -> member.getName().equals(name)) - .findAny(); - } - - @Override - public List findAll() { - return new ArrayList<>(store.values()); - } - - public void clearStore(){ - store.clear(); - } -} diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/service/MemberService.java b/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/service/MemberService.java deleted file mode 100644 index f1aafc6a..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/service/MemberService.java +++ /dev/null @@ -1,60 +0,0 @@ -package hello.hello_spring.service; - -import hello.hello_spring.domain.Member; -import hello.hello_spring.repository.MemberRepository; -import hello.hello_spring.repository.MemoryMemberRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; - - -@Transactional (readOnly = true) -public class MemberService { - - private final MemberRepository memberRepository; - - @Autowired - public MemberService (MemberRepository memberRepository) { - this.memberRepository = memberRepository; - } - - /** - * νšŒμ› κ°€μž… - **/ - @Transactional - public Long join(Member member) { - //같은 이름이 μžˆλŠ” 쀑볡 νšŒμ›μ€ λΆˆκ°€. - - // result.get() 을 μ΄μš©ν•˜λ©΄ μ‹€μ œ κ·Έ νšŒμ› 정보λ₯Ό κ°€μ Έμ˜¬μˆ˜ 있음. - -// Optional result = memberRepository.findByName(member.getName()); -// result.ifPresent(m -> { -// throw new IllegalStateException("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); -// }); - - validateDuplicateMember(member); - memberRepository.save(member); - return member.getId(); - } - - private void validateDuplicateMember(Member member) { - memberRepository.findByName(member.getName()) - .ifPresent(m -> { - throw new IllegalStateException("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); - }); - } - - /** - * μ „μ²΄νšŒμ›μ‘°νšŒ - * */ - public List findMembers() { - return memberRepository.findAll(); - } - - public Optional findOne(Long memberId) { - return memberRepository.findById(memberId); - } -} diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/application.properties b/ajwoong/hello-spring/hello-spring/src/main/resources/application.properties deleted file mode 100644 index 4082b06a..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/application.properties +++ /dev/null @@ -1,8 +0,0 @@ -spring.application.name=hello-spring - -spring.datasource.url= jdbc:h2:tcp://localhost/~/test -spring.datasource.driver-class-name=org.h2.Driver -spring.datasource.username=sa - -spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=update diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/static/index.html b/ajwoong/hello-spring/hello-spring/src/main/resources/static/index.html deleted file mode 100644 index 8825a999..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/static/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - Hello - - -Hello -hello - - \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/members/createMemberForm.html b/ajwoong/hello-spring/hello-spring/src/main/resources/templates/members/createMemberForm.html deleted file mode 100644 index 08884fd0..00000000 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/members/createMemberForm.html +++ /dev/null @@ -1,14 +0,0 @@ - - - -
-
-
- - -
- -
-
- - \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/repository/MemoryMemberRepositoryTest.java b/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/repository/MemoryMemberRepositoryTest.java deleted file mode 100644 index 75050d04..00000000 --- a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/repository/MemoryMemberRepositoryTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package hello.hello_spring.repository; - -import static org.assertj.core.api.Assertions.*; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import hello.hello_spring.domain.Member; - -import java.util.List; - -class MemoryMemberRepositoryTest { - MemoryMemberRepository repository = new MemoryMemberRepository(); - - @AfterEach - public void afterEach(){ - repository.clearStore(); - } - - @Test - public void save(){ - Member member = new Member(); - member.setName("Spring"); - - repository.save(member); - - Member result = repository.findById(member.getId()).get(); - assertThat(member).isEqualTo(result); - //Assertions.assertEquals(member, result); -// System.out.println("result = " + (result == member)); - } - - @Test - public void findByName(){ - Member member1 = new Member(); - member1.setName("Spring1"); - repository.save(member1); - - Member member2 = new Member(); - member2.setName("Spring2"); - repository.save(member2); - - Member result =repository.findByName("Spring1").get(); - - assertThat(member1).isEqualTo(result); - - } - - @Test - public void findAll(){ - Member member1 = new Member(); - member1.setName("Spring1"); - repository.save(member1); - - Member member2 = new Member(); - member2.setName("Spring2"); - repository.save(member2); - - Member member3 = new Member(); - member3.setName("Spring3"); - repository.save(member3); - - List members = repository.findAll(); - - assertThat(members.size()).isEqualTo(3); - - } - -// @Test -// public void findById(){ -// Member member = new Member(); -// member.setName("Spring1"); -// repository.save(member); -// -// -// -// Member result = repository.findById(member.getId()).get(); -// assertThat(result).isEqualTo(member); -// } - - -} diff --git a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceTest.java b/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceTest.java deleted file mode 100644 index 3d8226f1..00000000 --- a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package hello.hello_spring.service; - -import hello.hello_spring.domain.Member; -import static org.assertj.core.api.Assertions.*; - -import hello.hello_spring.repository.MemoryMemberRepository; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -class MemberServiceTest { - - MemberService memberService; - MemoryMemberRepository memberRepository; - - @BeforeEach - public void beforeEach(){ - memberRepository = new MemoryMemberRepository(); - memberService = new MemberService(memberRepository); - } - - @AfterEach - public void afterEach(){ - memberRepository.clearStore(); - } - - @Test - void νšŒμ›κ°€μž…() { - //given - Member member = new Member(); - member.setName("hello"); - - //when - Long saveId = memberService.join(member); - - //then - Member findMember = memberService.findOne(saveId).get(); - assertThat(member.getName()).isEqualTo(findMember.getName()); - - } - - @Test - public void 쀑볡_νšŒμ›_μ˜ˆμ™Έ(){ - //given - Member member1 = new Member(); - member1.setName("spring"); - - Member member2 = new Member(); - member2.setName("spring"); - //when -// memberService.join(member1); -// try{ -// memberService.join(member2); -// fail(); -// } catch (IllegalStateException e){ -// assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); -// } - - memberService.join(member1); - IllegalStateException e = assertThrows(IllegalStateException.class, () -> memberService.join(member2)); - - assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); - - - //then - - } - - @Test - void findMembers() { - //given - Member member1 = new Member(); - member1.setName("jewoong"); - memberService.join(member1); - - Member member2 = new Member(); - member2.setName("zerry"); - memberService.join(member2); - - //when - List members = memberService.findMembers(); - //then - - assertThat(members.size()).isEqualTo(2); - } - - @Test - void findOne() { - Member member1 = new Member(); - member1.setName("mega"); - Long saveId = memberService.join(member1); - - - Member findMember = memberService.findOne(saveId).get(); - assertThat(findMember.getId()).isEqualTo(member1.getId()); - - - } -} \ No newline at end of file diff --git a/oneeee822/hello-spring/.gitignore b/chan0831/core/.gitignore similarity index 97% rename from oneeee822/hello-spring/.gitignore rename to chan0831/core/.gitignore index c2065bc2..a281dd40 100644 --- a/oneeee822/hello-spring/.gitignore +++ b/chan0831/core/.gitignore @@ -35,3 +35,4 @@ out/ ### VS Code ### .vscode/ +.DS_Store diff --git a/chan0831/core/build.gradle b/chan0831/core/build.gradle new file mode 100644 index 00000000..274e81b4 --- /dev/null +++ b/chan0831/core/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.2.4' + id 'io.spring.dependency-management' version '1.1.4' +} + +group = 'hello' +version = '0.0.1-SNAPSHOT' + +java { + sourceCompatibility = '21' +} +//λ‘¬λ³΅μ‹œμž‘ +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} +//둬볡 끝 + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter' + implementation 'jakarta.inject:jakarta.inject-api:2.0.1' + implementation 'org.springframework.boot:spring-boot-starter-web' + //둬볡 라이브러리 μ‹œμž‘ + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + testCompileOnly'org.projectlombok:lombok' + testAnnotationProcessor 'org.projetlombok:lombok' + //둬볡 라이브러리 끝 + + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/ajwoong/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.jar b/chan0831/core/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from ajwoong/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.jar rename to chan0831/core/gradle/wrapper/gradle-wrapper.jar diff --git a/ajwoong/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.properties b/chan0831/core/gradle/wrapper/gradle-wrapper.properties similarity index 94% rename from ajwoong/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.properties rename to chan0831/core/gradle/wrapper/gradle-wrapper.properties index a4413138..b82aa23a 100644 --- a/ajwoong/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.properties +++ b/chan0831/core/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/ajwoong/hello-spring/hello-spring/gradlew b/chan0831/core/gradlew old mode 100644 new mode 100755 similarity index 98% rename from ajwoong/hello-spring/hello-spring/gradlew rename to chan0831/core/gradlew index b740cf13..1aa94a42 --- a/ajwoong/hello-spring/hello-spring/gradlew +++ b/chan0831/core/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. diff --git a/ajwoong/hello-spring/hello-spring/gradlew.bat b/chan0831/core/gradlew.bat similarity index 96% rename from ajwoong/hello-spring/hello-spring/gradlew.bat rename to chan0831/core/gradlew.bat index 25da30db..7101f8e4 100644 --- a/ajwoong/hello-spring/hello-spring/gradlew.bat +++ b/chan0831/core/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/chan0831/core/settings.gradle b/chan0831/core/settings.gradle new file mode 100644 index 00000000..4d52ac57 --- /dev/null +++ b/chan0831/core/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'core' diff --git a/chan0831/core/src/main/java/hello/core/AppConfig.java b/chan0831/core/src/main/java/hello/core/AppConfig.java new file mode 100644 index 00000000..21d1b934 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/AppConfig.java @@ -0,0 +1,38 @@ +package hello.core; + +import hello.core.discount.DiscountPolicy; +import hello.core.discount.RateDiscountPolicy; +import hello.core.member.MemberRepository; +import hello.core.member.MemberService; +import hello.core.member.MemberServiceImpl; +import hello.core.member.MemoryMemberRepository; +import hello.core.order.OrderService; +import hello.core.order.OrderServiceImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AppConfig { + @Bean + public MemberService memberService(){ + System.out.println("call AppConfig.memberService"); + return new MemberServiceImpl(memoryRepository()); + + } + @Bean + private static MemberRepository memoryRepository() { + + System.out.println("call AppConfig.memberRepository"); + return new MemoryMemberRepository(); + } + @Bean + public OrderService orderService(){ + + System.out.println("call AppConfig.orderService"); + return new OrderServiceImpl(memoryRepository(), discountPolicy() ); + } + @Bean + public DiscountPolicy discountPolicy(){ + return new RateDiscountPolicy(); + } +} diff --git a/chan0831/core/src/main/java/hello/core/AutoAppConfig.java b/chan0831/core/src/main/java/hello/core/AutoAppConfig.java new file mode 100644 index 00000000..f68d692d --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/AutoAppConfig.java @@ -0,0 +1,14 @@ +package hello.core; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; + +@Configuration +@ComponentScan( + basePackages = "hello.core", + excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Configuration.class) +)//AppConfigμˆ˜λ™λ“±λ‘ μ œμ™Έ + +public class AutoAppConfig { +} diff --git a/chan0831/core/src/main/java/hello/core/CoreApplication.java b/chan0831/core/src/main/java/hello/core/CoreApplication.java new file mode 100644 index 00000000..5bc183f2 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/CoreApplication.java @@ -0,0 +1,13 @@ +package hello.core; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CoreApplication { + + public static void main(String[] args) { + SpringApplication.run(CoreApplication.class, args); + } + +} diff --git a/chan0831/core/src/main/java/hello/core/OrderApp.java b/chan0831/core/src/main/java/hello/core/OrderApp.java new file mode 100644 index 00000000..f8781773 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/OrderApp.java @@ -0,0 +1,31 @@ +package hello.core; + +import hello.core.member.Grade; +import hello.core.member.Member; +import hello.core.member.MemberService; +import hello.core.member.MemberServiceImpl; +import hello.core.order.Order; +import hello.core.order.OrderService; +import hello.core.order.OrderServiceImpl; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class OrderApp { + public static void main(String[] args) { + +// AppConfig appConfig = new AppConfig(); +// MemberService memberService = appConfig.memberService(); +// OrderService orderService = appConfig.orderService(); + ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class); + + MemberService memberService = applicationContext.getBean("memberService", MemberService.class); + OrderService orderService = applicationContext.getBean("orderService", OrderService.class); + + Long memberId = 1L; + Member member = new Member(memberId,"memberA", Grade.VIP); + memberService.join(member); + + Order order = orderService.createOrder(memberId, "itemA", 10000); + System.out.println("order = " + order); + } +} diff --git a/chan0831/core/src/main/java/hello/core/discount/DiscountPolicy.java b/chan0831/core/src/main/java/hello/core/discount/DiscountPolicy.java new file mode 100644 index 00000000..545752dd --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/discount/DiscountPolicy.java @@ -0,0 +1,8 @@ +package hello.core.discount; + +import hello.core.member.Member; + +public interface DiscountPolicy { + + int discount(Member member, int price); +} diff --git a/chan0831/core/src/main/java/hello/core/discount/FixDiscountPolicy.java b/chan0831/core/src/main/java/hello/core/discount/FixDiscountPolicy.java new file mode 100644 index 00000000..f4094749 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/discount/FixDiscountPolicy.java @@ -0,0 +1,18 @@ +package hello.core.discount; + +import hello.core.member.Grade; +import hello.core.member.Member; +import org.springframework.stereotype.Component; + +@Component + +public class FixDiscountPolicy implements DiscountPolicy { + private int discountFixAmount = 1000; + + @Override + public int discount(Member member, int price){ + if(member.getGrade() == Grade.VIP){ + return discountFixAmount; + }else return 0; + } +} diff --git a/chan0831/core/src/main/java/hello/core/discount/RateDiscountPolicy.java b/chan0831/core/src/main/java/hello/core/discount/RateDiscountPolicy.java new file mode 100644 index 00000000..cf181944 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/discount/RateDiscountPolicy.java @@ -0,0 +1,21 @@ +package hello.core.discount; + +import hello.core.member.Grade; +import hello.core.member.Member; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@Component + +public class RateDiscountPolicy implements DiscountPolicy { + private int discountPercent = 10; + + @Override + public int discount(Member member, int price){ + if(member.getGrade()== Grade.VIP){ + return price * discountPercent/ 100 ; + }else{ + return 0; + } + } +} diff --git a/chan0831/core/src/main/java/hello/core/member/Grade.java b/chan0831/core/src/main/java/hello/core/member/Grade.java new file mode 100644 index 00000000..567399b8 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/member/Grade.java @@ -0,0 +1,6 @@ +package hello.core.member; + +public enum Grade { + BASIC, + VIP +} diff --git a/chan0831/core/src/main/java/hello/core/member/Member.java b/chan0831/core/src/main/java/hello/core/member/Member.java new file mode 100644 index 00000000..cda68dc4 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/member/Member.java @@ -0,0 +1,37 @@ +package hello.core.member; + +public class Member { + private Long id; + private String name; + private Grade grade; + + public Member(Long id, String name, Grade grade) { + this.id = id; + this.name = name; + this.grade = grade; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Grade getGrade() { + return grade; + } + + public void setGrade(Grade grade) { + this.grade = grade; + } +} diff --git a/chan0831/core/src/main/java/hello/core/member/MemberRepository.java b/chan0831/core/src/main/java/hello/core/member/MemberRepository.java new file mode 100644 index 00000000..fd2b4a3f --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/member/MemberRepository.java @@ -0,0 +1,11 @@ +package hello.core.member; + +import org.springframework.stereotype.Component; + +@Component +public interface MemberRepository { + + void save(Member member); + + Member findById(Long memberId); +} diff --git a/chan0831/core/src/main/java/hello/core/member/MemberService.java b/chan0831/core/src/main/java/hello/core/member/MemberService.java new file mode 100644 index 00000000..6abd3b2e --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/member/MemberService.java @@ -0,0 +1,10 @@ +package hello.core.member; + +import org.springframework.stereotype.Component; + +@Component +public interface MemberService { + void join(Member member); + + Member findMember(Long MemberId); +} diff --git a/chan0831/core/src/main/java/hello/core/member/MemberServiceImpl.java b/chan0831/core/src/main/java/hello/core/member/MemberServiceImpl.java new file mode 100644 index 00000000..f732e25e --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/member/MemberServiceImpl.java @@ -0,0 +1,29 @@ +package hello.core.member; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class MemberServiceImpl implements MemberService{ + + private final MemberRepository memberRepository; + + @Autowired + public MemberServiceImpl(MemberRepository memberRepository){ + this.memberRepository = memberRepository; + } + + @Override + public void join(Member member) { + memberRepository.save(member); + } + + @Override + public Member findMember(Long memberId) { + return memberRepository.findById(memberId); + } + //ν…ŒμŠ€νŠΈμš©λ„ + public MemberRepository getMemberRepository(){ + return memberRepository; + } +} diff --git a/chan0831/core/src/main/java/hello/core/member/MemoryMemberRepository.java b/chan0831/core/src/main/java/hello/core/member/MemoryMemberRepository.java new file mode 100644 index 00000000..f5311741 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/member/MemoryMemberRepository.java @@ -0,0 +1,24 @@ +package hello.core.member; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + + +public class MemoryMemberRepository implements MemberRepository { + private static Map store = new HashMap<>(); + + @Override + public void save(Member member) { + store.put(member.getId(),member); + } + + @Override + public Member findById(Long memberId) { + return store.get(memberId); + } + + +} diff --git a/chan0831/core/src/main/java/hello/core/memberApp.java b/chan0831/core/src/main/java/hello/core/memberApp.java new file mode 100644 index 00000000..52639773 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/memberApp.java @@ -0,0 +1,23 @@ +package hello.core; + +import hello.core.member.Grade; +import hello.core.member.Member; +import hello.core.member.MemberService; +import hello.core.member.MemberServiceImpl; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class memberApp { + public static void main(String[] args) { +// AppConfig appConfig = new AppConfig(); +// MemberService memberService = appConfig.memberService(); + ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class); + MemberService memberService = applicationContext.getBean("memberService", MemberService.class); + Member member = new Member(1L, "memberA", Grade.VIP); + memberService.join(member); + + Member findMember = memberService.findMember(1L); + System.out.println("new member : " + member.getName()); + System.out.println("find member :" + findMember.getName()); + } +} diff --git a/chan0831/core/src/main/java/hello/core/order/Order.java b/chan0831/core/src/main/java/hello/core/order/Order.java new file mode 100644 index 00000000..b16de86e --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/order/Order.java @@ -0,0 +1,62 @@ +package hello.core.order; + +public class Order { + + private Long memberId; + private String itemName; + private int itemPrice; + private int discountPrice; + + public Order(Long memberId, String itemName, int itemPrice, int discountPrice) { + this.memberId = memberId; + this.itemName = itemName; + this.itemPrice = itemPrice; + this.discountPrice = discountPrice; + } + + public int calculatPrice() { + return itemPrice - discountPrice; + } + + public Long getMemberId() { + return memberId; + } + + public void setMemberId(Long memberId) { + this.memberId = memberId; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public int getItemPrice() { + return itemPrice; + } + + public void setItemPrice(int itemPrice) { + this.itemPrice = itemPrice; + } + + public int getDiscountPrice() { + return discountPrice; + } + + public void setDiscountPrice(int discountPrice) { + this.discountPrice = discountPrice; + } + + @Override + public String toString() { + return "Order(" + + "memberId=" + memberId + + ", itemName=" + itemName + '\'' + + ", itemPrice=" + itemPrice + + ", discountPrice=" + discountPrice + + '}'; + } +} diff --git a/chan0831/core/src/main/java/hello/core/order/OrderService.java b/chan0831/core/src/main/java/hello/core/order/OrderService.java new file mode 100644 index 00000000..92667712 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/order/OrderService.java @@ -0,0 +1,5 @@ +package hello.core.order; + +public interface OrderService { + Order createOrder(Long memberId, String itemName, int itemPrice ); +} diff --git a/chan0831/core/src/main/java/hello/core/order/OrderServiceImpl.java b/chan0831/core/src/main/java/hello/core/order/OrderServiceImpl.java new file mode 100644 index 00000000..75571544 --- /dev/null +++ b/chan0831/core/src/main/java/hello/core/order/OrderServiceImpl.java @@ -0,0 +1,42 @@ +package hello.core.order; + +import hello.core.discount.DiscountPolicy; +import hello.core.discount.FixDiscountPolicy; +import hello.core.discount.RateDiscountPolicy; +import hello.core.member.Member; +import hello.core.member.MemberRepository; +import hello.core.member.MemoryMemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class OrderServiceImpl implements OrderService{ + + private final MemberRepository memberRepository ; + private final DiscountPolicy discountPolicy ; + + @Autowired + public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) { + this.memberRepository = memberRepository; + this.discountPolicy = discountPolicy; + } + + + + + + @Override + public Order createOrder(Long memberId, String itemName, int itemPrice) { + + Member member = memberRepository.findById(memberId); + int discountPrice = discountPolicy.discount(member,itemPrice); + + return new Order(memberId , itemName, itemPrice, discountPrice); + } + + //test + public MemberRepository getMemberRepository(){ + return memberRepository; + } +} diff --git a/chan0831/core/src/main/resources/appConfig.xml b/chan0831/core/src/main/resources/appConfig.xml new file mode 100644 index 00000000..30290a6a --- /dev/null +++ b/chan0831/core/src/main/resources/appConfig.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/chan0831/core/src/main/resources/application.properties b/chan0831/core/src/main/resources/application.properties new file mode 100644 index 00000000..061bbe4e --- /dev/null +++ b/chan0831/core/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=core diff --git a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/HelloSpringApplicationTests.java b/chan0831/core/src/test/java/hello/core/CoreApplicationTests.java similarity index 70% rename from ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/HelloSpringApplicationTests.java rename to chan0831/core/src/test/java/hello/core/CoreApplicationTests.java index 4b93a19b..90937b13 100644 --- a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/HelloSpringApplicationTests.java +++ b/chan0831/core/src/test/java/hello/core/CoreApplicationTests.java @@ -1,10 +1,10 @@ -package hello.hello_spring; +package hello.core; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class HelloSpringApplicationTests { +class CoreApplicationTests { @Test void contextLoads() { diff --git a/chan0831/core/src/test/java/hello/core/beandefinition/BeanDefinitionTest.java b/chan0831/core/src/test/java/hello/core/beandefinition/BeanDefinitionTest.java new file mode 100644 index 00000000..414d36d8 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/beandefinition/BeanDefinitionTest.java @@ -0,0 +1,27 @@ +package hello.core.beandefinition; + +import hello.core.AppConfig; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class BeanDefinitionTest { + AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); + //ApplicationContext ac = new ~~~ λŠ” getBeanDefinition을 λͺ»ν•˜κΈ° λ•Œλ¬Έμ— μ“°μ§€ μ•Šμ•˜λ‹€. + //ν‰μ†Œμ— 빈 λ°ν”Όλ‹ˆμ…˜μ„ κΊΌλ‚΄ μ“Έ 일 이 거의 μ—†κΈ° λ•Œλ¬Έμ— κΈ°λŠ₯이 μ—†μŒ. + //μ–΄λ…Έν…Œμ΄μ…˜μ„ ν†΅ν•˜λ©΄ νŒ©ν† λ¦¬ λΉˆμ„ 톡해 정보가 λ“±λ‘λœλ‹€. 정보가 μ§μ ‘μ μœΌλ‘œ λ“œλŸ¬λ‚˜μ§€ μ•ŠλŠ”λ‹€. + //λ°˜λŒ€λ‘œ 이전에 μ“°λ˜ xml λ°©μ‹μ—μ„œλŠ” λΉˆμ— λŒ€ν•œ 정보가 λͺ…ν™•ν•˜κ²Œ λ“œλŸ¬λ‚œλ‹€. + @Test + @DisplayName("빈 μ„€μ • 메타정보 확인") + void findApplicationBean(){ + String[] beanDefinitionNames = ac. getBeanDefinitionNames(); + for (String beanDefinitionName : beanDefinitionNames) { + BeanDefinition beanDefinition = ac.getBeanDefinition(beanDefinitionName); + + if(beanDefinition.getRole()==BeanDefinition.ROLE_APPLICATION){ + System.out.println("beanDefinitionName = "+ beanDefinitionName + " beanDefinition= " + beanDefinition); + } + } + } +} diff --git a/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextBasicFindTest.java b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextBasicFindTest.java new file mode 100644 index 00000000..f6fd41d3 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextBasicFindTest.java @@ -0,0 +1,45 @@ +package hello.core.beanfind; + +import hello.core.AppConfig; +import hello.core.member.MemberService; +import hello.core.member.MemberServiceImpl; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ApplicationContextBasicFindTest { + + AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); + + @Test + @DisplayName("빈 μ΄λ¦„μœΌλ‘œ 쑰회") + void findBeanByName(){ + MemberService memberService = ac.getBean("memberService", MemberService.class); + assertThat(memberService).isInstanceOf(MemberServiceImpl.class); + } + + @Test + @DisplayName("이름없이 νƒ€μž…μœΌλ‘œλ§Œ 쑰회") + void findBeanByType(){ + MemberService memberService = ac.getBean(MemberService.class); + assertThat(memberService).isInstanceOf(MemberServiceImpl.class); + } + + @Test + @DisplayName("ꡬ체 νƒ€μž…μœΌλ‘œ 쑰회") + void findBeanByName2(){ + MemberServiceImpl memberService = ac.getBean("memberService", MemberServiceImpl.class); + assertThat(memberService).isInstanceOf(MemberServiceImpl.class); + } + + @Test + @DisplayName("빈 μ΄λ¦„μœΌλ‘œ 쑰회 X") + void findBeanByNameX(){ + org.junit.jupiter.api.Assertions.assertThrows(NoSuchBeanDefinitionException.class, + () -> ac.getBean("xxxxx", MemberService.class)); + } + +} diff --git a/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextExtendsFindTest.java b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextExtendsFindTest.java new file mode 100644 index 00000000..a592a52b --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextExtendsFindTest.java @@ -0,0 +1,76 @@ +package hello.core.beanfind; + +import hello.core.discount.DiscountPolicy; +import hello.core.discount.FixDiscountPolicy; +import hello.core.discount.RateDiscountPolicy; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoUniqueBeanDefinitionException; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ApplicationContextExtendsFindTest { + AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(TestConfig.class); + + @Test + @DisplayName("λΆ€λͺ¨ νƒ€μž…μœΌλ‘œ μ‘°νšŒμ‹œ μžμ‹μ΄ λ‘˜ 이상 있으면 쀑볡 였λ₯˜ λ°œμƒ") + void findBeanByParentTypeDuplicate() { + assertThrows(NoUniqueBeanDefinitionException.class, + () -> ac.getBean(DiscountPolicy.class)); + + } + + @Test + @DisplayName("λΆ€λͺ¨ νƒ€μž…μœΌλ‘œ μ‘°νšŒμ‹œ μžμ‹μ΄ λ‘˜ 이상 있으면 빈 이름을 μ§€μ •ν•˜λ©΄ λœλ‹€.") + void findBeanByParentTypeBeanName() { + DiscountPolicy rateDiscountPolicy = ac.getBean("rateDiscountPolicy", DiscountPolicy.class); + assertThat(rateDiscountPolicy).isInstanceOf(RateDiscountPolicy.class); + + } + + @Test + @DisplayName("νŠΉμ • ν•˜μœ„ νƒ€μž…μœΌλ‘œ 쑰회") + void findBeanBySubType() { + RateDiscountPolicy bean = ac.getBean(RateDiscountPolicy.class); + assertThat(bean).isInstanceOf(RateDiscountPolicy.class); + } + + @Test + @DisplayName("λΆ€λͺ¨ νƒ€μž…μœΌλ‘œ λͺ¨λ‘ μ‘°νšŒν•˜κΈ°") + void findAllBeanByParentType() { + Map beansOfType = ac.getBeansOfType(DiscountPolicy.class); + assertThat(beansOfType.size()).isEqualTo(2); + for (String key : beansOfType.keySet()) { + System.out.println("key = "+ key + " values = " + beansOfType.get(key)); + } + } + + @Test + @DisplayName("λΆ€λͺ¨ νƒ€μž…μœΌλ‘œ λͺ¨λ‘ μ‘°νšŒν•˜κΈ° - Object") + void findAllBeanByObjectType() { + Map beansOfType = ac.getBeansOfType(Object.class); + for (String key : beansOfType.keySet()) { + System.out.println("key = "+ key + " values = " + beansOfType.get(key)); + } + } + + @Configuration + static class TestConfig{ + + @Bean + public DiscountPolicy rateDiscountPolicy(){ + return new RateDiscountPolicy(); + } + + @Bean + public DiscountPolicy fixDiscountPolicy(){ + return new FixDiscountPolicy(); + } + } +} diff --git a/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextInfoTest.java b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextInfoTest.java new file mode 100644 index 00000000..de2f7655 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextInfoTest.java @@ -0,0 +1,39 @@ +package hello.core.beanfind; + +import hello.core.AppConfig; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class ApplicationContextInfoTest { + + AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); + + @Test + @DisplayName("λͺ¨λ“  빈 좜λ ₯ν•˜κΈ°") + void findAllBean(){ + String[] beanDefinitionNames = ac.getBeanDefinitionNames(); + for (String beanDefinitionName : beanDefinitionNames) { + Object bean = ac.getBean(beanDefinitionName); + System.out.println("name =" + beanDefinitionName + " object = "+ bean); + + } + } + + @Test + @DisplayName("μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 빈 좜λ ₯ν•˜κΈ°") + void findApplicationBean(){ + String[] beanDefinitionNames = ac.getBeanDefinitionNames(); + for (String beanDefinitionName : beanDefinitionNames) { + BeanDefinition beanDefinition = ac.getBeanDefinition(beanDefinitionName); + + //Role ROLE_APPLICATION; 직접 λ“±λ‘ν•œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 빈 + //Role ROLE_INFRASTRUCTURE; μŠ€ν”„λ§μ΄ λ‚΄λΆ€μ—μ„œ μ‚¬μš©ν•˜λŠ” 빈 + if(beanDefinition.getRole()== BeanDefinition.ROLE_APPLICATION){ + Object bean = ac.getBean(beanDefinitionName); + System.out.println("name =" + beanDefinitionName + " object = "+ bean); + } + } + } +} diff --git a/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextSameBeanFindTest.java b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextSameBeanFindTest.java new file mode 100644 index 00000000..633bb348 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/beanfind/ApplicationContextSameBeanFindTest.java @@ -0,0 +1,59 @@ +package hello.core.beanfind; + +import hello.core.member.MemberRepository; +import hello.core.member.MemoryMemberRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoUniqueBeanDefinitionException; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ApplicationContextSameBeanFindTest { + + AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(SameBeanConfig.class); + + @Test + @DisplayName("νƒ€μž…μœΌλ‘œ μ‘°νšŒμ‹œ 같은 νƒ€μž…μ΄ λ‘˜ 이상 있으면 쀑볡 였λ₯˜ λ°œμƒ") + void findBeanByTypeDupicate(){ + MemberRepository bean = ac.getBean(MemberRepository.class); + assertThrows(NoUniqueBeanDefinitionException.class, + () -> ac.getBean(MemberRepository.class)); + } + + @Test + @DisplayName("νƒ€μž…μœΌλ‘œ μ‘°νšŒμ‹œ 같은 νƒ€μž…μ΄ λ‘˜ 이상 있으면 빈 이름을 μ§€μ •ν•˜λ©΄ λœλ‹€.") + void findBeanByName(){ + MemberRepository memberRepository = ac.getBean("memberRepository1",MemberRepository.class); + assertThat(memberRepository).isInstanceOf(MemberRepository.class); + } + + @Test + @DisplayName("νŠΉμ • νƒ€μž…μ„ λͺ¨λ‘ 쑰회") + void findAllBeanByType(){ + Map beansOfType = ac.getBeansOfType(MemberRepository.class); + for (String key : beansOfType.keySet()) { + System.out.println("key = " + key + " value = " + beansOfType.get(key)); + } + System.out.println("beansOfType = " + beansOfType); + assertThat(beansOfType.size()).isEqualTo(2); + } + + @Configuration + static class SameBeanConfig{ + @Bean + public MemberRepository memberRepository1(){ + return new MemoryMemberRepository(); + } + + @Bean + public MemberRepository memberRepository2(){ + return new MemoryMemberRepository(); + } + } +} diff --git a/chan0831/core/src/test/java/hello/core/discount/RateDiscountPolicyTest.java b/chan0831/core/src/test/java/hello/core/discount/RateDiscountPolicyTest.java new file mode 100644 index 00000000..a7c5a9b8 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/discount/RateDiscountPolicyTest.java @@ -0,0 +1,37 @@ +package hello.core.discount; + +import hello.core.member.Grade; +import hello.core.member.Member; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class RateDiscountPolicyTest { + + RateDiscountPolicy discountPolicy = new RateDiscountPolicy(); + + @Test + @DisplayName("VIPλŠ” 10% 할인이 μ μš©λ˜μ–΄μ•Ό ν•œλ‹€.") + void vip_o(){ + //given + Member member = new Member(1L, "memberVIP", Grade.VIP); + //when + int discount= discountPolicy.discount(member,10000); + //then + Assertions.assertThat(discount).isEqualTo(1000); + } + + @Test + @DisplayName("VIPκ°€ μ•„λ‹ˆλ©΄ 할인이 μ μš©λ˜μ§€ μ•Šμ•„μ•Ό ν•œλ‹€.") + void vip_x() { + //given + Member member = new Member(2L, "memberBASIC", Grade.BASIC); + //when + int discount= discountPolicy.discount(member,10000); + //then + Assertions.assertThat(discount).isEqualTo(0); + } + +} \ No newline at end of file diff --git a/chan0831/core/src/test/java/hello/core/member/MemberServiceTest.java b/chan0831/core/src/test/java/hello/core/member/MemberServiceTest.java new file mode 100644 index 00000000..45d1fe18 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/member/MemberServiceTest.java @@ -0,0 +1,27 @@ +package hello.core.member; + +import hello.core.AppConfig; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class MemberServiceTest { + + MemberService memberService ; + @BeforeEach + public void beforeEach(){ + AppConfig appConfig = new AppConfig(); + memberService = appConfig.memberService(); + } + + @Test + void join() { + //given + Member member = new Member(1L,"memberA", Grade.VIP); + //when + memberService.join(member); + Member findMember = memberService.findMember(1L); + //then + Assertions.assertThat(member).isEqualTo(findMember); + } +} diff --git a/chan0831/core/src/test/java/hello/core/order/OrderServiceTest.java b/chan0831/core/src/test/java/hello/core/order/OrderServiceTest.java new file mode 100644 index 00000000..045f4525 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/order/OrderServiceTest.java @@ -0,0 +1,31 @@ +package hello.core.order; + +import hello.core.AppConfig; +import hello.core.member.Grade; +import hello.core.member.Member; +import hello.core.member.MemberService; +import hello.core.member.MemberServiceImpl; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class OrderServiceTest { + MemberService memberService ; + OrderService orderService ; + @BeforeEach + public void beforeEach(){ + AppConfig appConfig = new AppConfig(); + memberService = appConfig.memberService(); + orderService = appConfig.orderService(); + } + + @Test + void createOrder(){ + Long memberId = 1L; + Member member = new Member(memberId,"memberA", Grade.VIP); + memberService.join(member); + + Order order = orderService.createOrder(memberId,"itemA", 10000); + Assertions.assertThat(order.getDiscountPrice()).isEqualTo(1000); + } +} diff --git a/chan0831/core/src/test/java/hello/core/scan/AutoAppConfigTest.java b/chan0831/core/src/test/java/hello/core/scan/AutoAppConfigTest.java new file mode 100644 index 00000000..77731820 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/scan/AutoAppConfigTest.java @@ -0,0 +1,18 @@ +package hello.core.scan; + +import hello.core.member.MemberService; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AutoAppConfigTest { + + @Test + void basicScan() { + AnnotationConfigApplicationContext ac= new AnnotationConfigApplicationContext(AutoAppConfigTest.class); + + MemberService memberService = ac.getBean(MemberService.class); + assertThat(memberService).isInstanceOf(MemberService.class); + } +} diff --git a/chan0831/core/src/test/java/hello/core/scan/Filter/BeanA.java b/chan0831/core/src/test/java/hello/core/scan/Filter/BeanA.java new file mode 100644 index 00000000..f60721d6 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/scan/Filter/BeanA.java @@ -0,0 +1,4 @@ +package hello.core.scan.Filter; +@MyIncludeComponet +public class BeanA { +} diff --git a/chan0831/core/src/test/java/hello/core/scan/Filter/BeanB.java b/chan0831/core/src/test/java/hello/core/scan/Filter/BeanB.java new file mode 100644 index 00000000..f1ca999e --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/scan/Filter/BeanB.java @@ -0,0 +1,4 @@ +package hello.core.scan.Filter; +@MyExcludeComponent +public class BeanB { +} diff --git a/chan0831/core/src/test/java/hello/core/scan/Filter/ComponentFilterAppConfigTest.java b/chan0831/core/src/test/java/hello/core/scan/Filter/ComponentFilterAppConfigTest.java new file mode 100644 index 00000000..2a5908de --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/scan/Filter/ComponentFilterAppConfigTest.java @@ -0,0 +1,30 @@ +package hello.core.scan.Filter; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; + +public class ComponentFilterAppConfigTest { + @Test + void filterScan(){ + ApplicationContext ac = new AnnotationConfigApplicationContext(ComponentFilterAppConfig.class); + BeanA beanA = ac.getBean("beanA", BeanA.class); + Assertions.assertThat(beanA).isNotNull(); + + ac.getBean("beanB", BeanB.class); + org.junit.jupiter.api.Assertions.assertThrows(NoSuchBeanDefinitionException.class, + () -> ac.getBean("beanB", BeanB.class)); + } + @Configuration + @ComponentScan( + includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = MyIncludeComponet.class), + excludeFilters = @ComponentScan.Filter( type = FilterType.ANNOTATION, classes =MyExcludeComponent.class)) + static class ComponentFilterAppConfig{ + + } +} diff --git a/chan0831/core/src/test/java/hello/core/scan/Filter/MyExcludeComponent.java b/chan0831/core/src/test/java/hello/core/scan/Filter/MyExcludeComponent.java new file mode 100644 index 00000000..f87a00e2 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/scan/Filter/MyExcludeComponent.java @@ -0,0 +1,10 @@ +package hello.core.scan.Filter; + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface MyExcludeComponent { + +} diff --git a/chan0831/core/src/test/java/hello/core/scan/Filter/MyIncludeComponet.java b/chan0831/core/src/test/java/hello/core/scan/Filter/MyIncludeComponet.java new file mode 100644 index 00000000..36f7fe99 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/scan/Filter/MyIncludeComponet.java @@ -0,0 +1,10 @@ +package hello.core.scan.Filter; + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface MyIncludeComponet { + +} diff --git a/chan0831/core/src/test/java/hello/core/singleton/ConfigurationSingletonTest.java b/chan0831/core/src/test/java/hello/core/singleton/ConfigurationSingletonTest.java new file mode 100644 index 00000000..5b524404 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/singleton/ConfigurationSingletonTest.java @@ -0,0 +1,42 @@ +package hello.core.singleton; + +import hello.core.AppConfig; +import hello.core.member.MemberRepository; +import hello.core.member.MemberServiceImpl; +import hello.core.order.OrderServiceImpl; +import org.junit.jupiter.api.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ConfigurationSingletonTest { + + @Test + void configurationTest() + { + ApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); + + MemberServiceImpl memberService = ac.getBean("memberService", MemberServiceImpl.class); + OrderServiceImpl orderService = ac.getBean("orderService", OrderServiceImpl.class); + MemberRepository memberRepository = ac.getBean("memberRepository", MemberRepository.class); + + MemberRepository memberRepository1 = memberService.getMemberRepository(); + MemberRepository memberRepository2 = orderService.getMemberRepository(); + System.out.println("memberRepository1 = " + memberRepository1); + System.out.println("memberRepository2 = " + memberRepository2); + System.out.println("MemberRepository = " + memberRepository); + + assertThat(memberService.getMemberRepository()).isSameAs(memberRepository); + assertThat(orderService.getMemberRepository()).isSameAs(memberRepository); + + } + + @Test + void configurationDeep(){ + ApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); + AppConfig bean = ac.getBean(AppConfig.class); + + System.out.println("bean = "+ bean.getClass()); + } +} diff --git a/chan0831/core/src/test/java/hello/core/singleton/SingletonService.java b/chan0831/core/src/test/java/hello/core/singleton/SingletonService.java new file mode 100644 index 00000000..8ee4292b --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/singleton/SingletonService.java @@ -0,0 +1,18 @@ +package hello.core.singleton; + +public class SingletonService { + + private static final SingletonService instance = new SingletonService(); + + public static SingletonService getInstance(){ + return instance; + } + + private SingletonService(){ + + }; + public void logic(){ + System.out.println("싱글톀 객체 둜직 호좜"); + } + +} diff --git a/chan0831/core/src/test/java/hello/core/singleton/SingletonServiceTest.java b/chan0831/core/src/test/java/hello/core/singleton/SingletonServiceTest.java new file mode 100644 index 00000000..1aa346e8 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/singleton/SingletonServiceTest.java @@ -0,0 +1,61 @@ +package hello.core.singleton; + +import hello.core.AppConfig; +import hello.core.member.MemberService; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class SingletonServiceTest { + + @Test + @DisplayName("μŠ€ν”„λ§ μ—†λŠ” μˆœμˆ˜ν•œ DI μ»¨ν…Œμ΄λ„ˆ") + void pureContainer(){ + AppConfig appConfig = new AppConfig(); + //1. 쑰회 : ν˜ΈμΆœν•  λ•Œ λ§ˆλ‹€ 객체λ₯Ό 생성 + MemberService memberService1 = appConfig.memberService(); + //2 쑰회 : ν˜ΈμΆœν•  λ•Œ λ§ˆλ‹€ 객체λ₯Ό 생성 + MemberService memberService2 = appConfig.memberService(); + + //μ°Έμ‘° 값이 λ‹€λ₯Έ 것을 확인 + System.out.println("memberService1 = " + memberService1); + System.out.println("memberService2 = " + memberService2); + + Assertions.assertThat(memberService1).isNotSameAs(memberService2); + + } + @Test + @DisplayName("싱글톀 νŒ¨ν„΄μ„ μ μš©ν•œ 객체 μ‚¬μš©") + void singletonServiceTest() { + SingletonService singletonService1 = SingletonService.getInstance(); + SingletonService singletonService2 = SingletonService.getInstance(); + + System.out.println("singletonService1 = " + singletonService1); + System.out.println("singletonService2 = " + singletonService2); + + Assertions.assertThat(singletonService1).isSameAs(singletonService2); + // λΆ€λ“±ν˜Έ 팁 : 1. same : μ›λž˜ μ‚¬μš©ν•˜λ˜ '=='κ³Ό κ°™λ‹€. 참쑰값비ꡐ + // 2. equal : μžλ°”μ— μžˆλŠ” equal κΈ°λŠ₯ + singletonService1.logic(); + } + + @Test + @DisplayName("μŠ€ν”„λ§ μ»¨ν…Œμ΄λ„ˆμ™€ 싱글톀") + void springContainer(){ + //AppConfig appConfig = new AppConfig(); + + ApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); + MemberService memberService1 = ac.getBean("memberService", MemberService.class); + MemberService memberService2 = ac.getBean("memberService", MemberService.class); + + //μ°Έμ‘° 값이 λ‹€λ₯Έ 것을 확인 + System.out.println("memberService1 = " + memberService1); + System.out.println("memberService2 = " + memberService2); + + Assertions.assertThat(memberService1).isSameAs(memberService2); + + } + +} diff --git a/chan0831/core/src/test/java/hello/core/singleton/StatefulService.java b/chan0831/core/src/test/java/hello/core/singleton/StatefulService.java new file mode 100644 index 00000000..c9318ff0 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/singleton/StatefulService.java @@ -0,0 +1,17 @@ +package hello.core.singleton; + +public class StatefulService { + + //private int price; // μƒνƒœλ₯Ό μœ μ§€ν•˜λŠ” ν•„λ“œ + + public int order(String name, int price){ + System.out.println("name = " + name + "price = " + price ); + // this.price = price; // 문제 λ°œμƒ + return price; + } + + //public int getPrice() { + // return price; + //} + +} diff --git a/chan0831/core/src/test/java/hello/core/singleton/StatefulServiceTest.java b/chan0831/core/src/test/java/hello/core/singleton/StatefulServiceTest.java new file mode 100644 index 00000000..4119b039 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/singleton/StatefulServiceTest.java @@ -0,0 +1,35 @@ +package hello.core.singleton; + +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; + +class StatefulServiceTest { + + @Test + void statefulServiceSingleton(){ + AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(TestConfig.class); + StatefulService statefulService1 = ac.getBean(StatefulService.class); + StatefulService statefulService2 = ac.getBean(StatefulService.class); + + //userA κ°€ 10000원 μ£Όλ¬Έ + int a = statefulService1.order("userA", 10000); + //userB κ°€ 20000원 μ£Όλ¬Έ + int b = statefulService2.order("userB", 20000); + + //ThreadA : userA μ£Όλ¬Έ κΈˆμ•‘ 쑰회 + //int price = statefulService1.(); + System.out.println("price = " + a); + + //Assertions.assertThat(statefulService1.getPrice()).isEqualTo(20000); + } + + static class TestConfig{ + + @Bean + public StatefulService statefulService() { + return new StatefulService(); + } + } + +} \ No newline at end of file diff --git a/chan0831/core/src/test/java/hello/core/xml/XmlAppContext.java b/chan0831/core/src/test/java/hello/core/xml/XmlAppContext.java new file mode 100644 index 00000000..f5c4e2b9 --- /dev/null +++ b/chan0831/core/src/test/java/hello/core/xml/XmlAppContext.java @@ -0,0 +1,18 @@ +package hello.core.xml; + +import hello.core.member.MemberService; +import org.junit.jupiter.api.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.GenericXmlApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +public class XmlAppContext { + + @Test + void xmlAppContext(){ + ApplicationContext ac = new GenericXmlApplicationContext("appConfig.xml"); + MemberService memberService = ac.getBean("memberService", MemberService.class); + assertThat(memberService).isInstanceOf(MemberService.class); + } +} diff --git a/chan0831/hello-spring/.gradle/8.7/checksums/checksums.lock b/chan0831/hello-spring/.gradle/8.7/checksums/checksums.lock new file mode 100644 index 00000000..a56882ee Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/checksums/checksums.lock differ diff --git a/chan0831/hello-spring/.gradle/8.7/checksums/md5-checksums.bin b/chan0831/hello-spring/.gradle/8.7/checksums/md5-checksums.bin new file mode 100644 index 00000000..c215370e Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/checksums/md5-checksums.bin differ diff --git a/chan0831/hello-spring/.gradle/8.7/checksums/sha1-checksums.bin b/chan0831/hello-spring/.gradle/8.7/checksums/sha1-checksums.bin new file mode 100644 index 00000000..b54e391f Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/checksums/sha1-checksums.bin differ diff --git a/chan0831/hello-spring/.gradle/8.7/dependencies-accessors/gc.properties b/chan0831/hello-spring/.gradle/8.7/dependencies-accessors/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/chan0831/hello-spring/.gradle/8.7/executionHistory/executionHistory.bin b/chan0831/hello-spring/.gradle/8.7/executionHistory/executionHistory.bin new file mode 100644 index 00000000..49bd0772 Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/executionHistory/executionHistory.bin differ diff --git a/chan0831/hello-spring/.gradle/8.7/executionHistory/executionHistory.lock b/chan0831/hello-spring/.gradle/8.7/executionHistory/executionHistory.lock new file mode 100644 index 00000000..fbe87216 Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/executionHistory/executionHistory.lock differ diff --git a/chan0831/hello-spring/.gradle/8.7/fileChanges/last-build.bin b/chan0831/hello-spring/.gradle/8.7/fileChanges/last-build.bin new file mode 100644 index 00000000..f76dd238 Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/fileChanges/last-build.bin differ diff --git a/chan0831/hello-spring/.gradle/8.7/fileHashes/fileHashes.bin b/chan0831/hello-spring/.gradle/8.7/fileHashes/fileHashes.bin new file mode 100644 index 00000000..4d313235 Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/fileHashes/fileHashes.bin differ diff --git a/chan0831/hello-spring/.gradle/8.7/fileHashes/fileHashes.lock b/chan0831/hello-spring/.gradle/8.7/fileHashes/fileHashes.lock new file mode 100644 index 00000000..57f733a0 Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/fileHashes/fileHashes.lock differ diff --git a/chan0831/hello-spring/.gradle/8.7/fileHashes/resourceHashesCache.bin b/chan0831/hello-spring/.gradle/8.7/fileHashes/resourceHashesCache.bin new file mode 100644 index 00000000..f8124295 Binary files /dev/null and b/chan0831/hello-spring/.gradle/8.7/fileHashes/resourceHashesCache.bin differ diff --git a/chan0831/hello-spring/.gradle/8.7/gc.properties b/chan0831/hello-spring/.gradle/8.7/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/chan0831/hello-spring/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/chan0831/hello-spring/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 00000000..6f92a921 Binary files /dev/null and b/chan0831/hello-spring/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/chan0831/hello-spring/.gradle/buildOutputCleanup/cache.properties b/chan0831/hello-spring/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 00000000..13b28e45 --- /dev/null +++ b/chan0831/hello-spring/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Sun Mar 31 17:56:33 KST 2024 +gradle.version=8.7 diff --git a/chan0831/hello-spring/.gradle/buildOutputCleanup/outputFiles.bin b/chan0831/hello-spring/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 00000000..a6165839 Binary files /dev/null and b/chan0831/hello-spring/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/chan0831/hello-spring/.gradle/file-system.probe b/chan0831/hello-spring/.gradle/file-system.probe new file mode 100644 index 00000000..2682171f Binary files /dev/null and b/chan0831/hello-spring/.gradle/file-system.probe differ diff --git a/chan0831/hello-spring/.gradle/vcs-1/gc.properties b/chan0831/hello-spring/.gradle/vcs-1/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.idea/.gitignore b/chan0831/hello-spring/.idea/.gitignore similarity index 100% rename from .idea/.gitignore rename to chan0831/hello-spring/.idea/.gitignore diff --git a/.idea/misc.xml b/chan0831/hello-spring/.idea/compiler.xml similarity index 50% rename from .idea/misc.xml rename to chan0831/hello-spring/.idea/compiler.xml index 639900d1..b86273d9 100644 --- a/.idea/misc.xml +++ b/chan0831/hello-spring/.idea/compiler.xml @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/chan0831/hello-spring/.idea/gradle.xml b/chan0831/hello-spring/.idea/gradle.xml new file mode 100644 index 00000000..a84091db --- /dev/null +++ b/chan0831/hello-spring/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/chan0831/hello-spring/.idea/jarRepositories.xml b/chan0831/hello-spring/.idea/jarRepositories.xml new file mode 100644 index 00000000..fdc392fe --- /dev/null +++ b/chan0831/hello-spring/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/chan0831/hello-spring/.idea/misc.xml b/chan0831/hello-spring/.idea/misc.xml new file mode 100644 index 00000000..32e588a1 --- /dev/null +++ b/chan0831/hello-spring/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/chan0831/hello-spring/.idea/uiDesigner.xml b/chan0831/hello-spring/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/chan0831/hello-spring/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/chan0831/hello-spring/.idea/vcs.xml similarity index 68% rename from .idea/vcs.xml rename to chan0831/hello-spring/.idea/vcs.xml index 35eb1ddf..b2bdec2d 100644 --- a/.idea/vcs.xml +++ b/chan0831/hello-spring/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/chan0831/hello-spring/HELP.md b/chan0831/hello-spring/HELP.md new file mode 100644 index 00000000..69a2a670 --- /dev/null +++ b/chan0831/hello-spring/HELP.md @@ -0,0 +1,29 @@ +# Read Me First +The following was discovered as part of building this project: + +* The original package name 'hello.hello-spring' is invalid and this project uses 'hello.hellospring' instead. + +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.2.4/gradle-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.2.4/gradle-plugin/reference/html/#build-image) +* [Spring Web](https://docs.spring.io/spring-boot/docs/3.2.4/reference/htmlsingle/index.html#web) +* [Thymeleaf](https://docs.spring.io/spring-boot/docs/3.2.4/reference/htmlsingle/index.html#web.servlet.spring-mvc.template-engines) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/chan0831/hello-spring/build/classes/java/main/hello/hellospring/HelloSpringApplication.class b/chan0831/hello-spring/build/classes/java/main/hello/hellospring/HelloSpringApplication.class new file mode 100644 index 00000000..61db1f14 Binary files /dev/null and b/chan0831/hello-spring/build/classes/java/main/hello/hellospring/HelloSpringApplication.class differ diff --git a/chan0831/hello-spring/build/classes/java/main/hello/hellospring/controller/HelloController.class b/chan0831/hello-spring/build/classes/java/main/hello/hellospring/controller/HelloController.class new file mode 100644 index 00000000..e0ddb47f Binary files /dev/null and b/chan0831/hello-spring/build/classes/java/main/hello/hellospring/controller/HelloController.class differ diff --git a/chan0831/hello-spring/build/classes/java/test/hello/hellospring/HelloSpringApplicationTests.class b/chan0831/hello-spring/build/classes/java/test/hello/hellospring/HelloSpringApplicationTests.class new file mode 100644 index 00000000..57e95e02 Binary files /dev/null and b/chan0831/hello-spring/build/classes/java/test/hello/hellospring/HelloSpringApplicationTests.class differ diff --git a/chan0831/hello-spring/build/libs/hello-spring-0.0.1-SNAPSHOT-plain.jar b/chan0831/hello-spring/build/libs/hello-spring-0.0.1-SNAPSHOT-plain.jar new file mode 100644 index 00000000..9eebaaf1 Binary files /dev/null and b/chan0831/hello-spring/build/libs/hello-spring-0.0.1-SNAPSHOT-plain.jar differ diff --git a/chan0831/hello-spring/build/libs/hello-spring-0.0.1-SNAPSHOT.jar b/chan0831/hello-spring/build/libs/hello-spring-0.0.1-SNAPSHOT.jar new file mode 100644 index 00000000..3863ca7b Binary files /dev/null and b/chan0831/hello-spring/build/libs/hello-spring-0.0.1-SNAPSHOT.jar differ diff --git a/chan0831/hello-spring/build/reports/tests/test/classes/hello.hellospring.HelloSpringApplicationTests.html b/chan0831/hello-spring/build/reports/tests/test/classes/hello.hellospring.HelloSpringApplicationTests.html new file mode 100644 index 00000000..e3014881 --- /dev/null +++ b/chan0831/hello-spring/build/reports/tests/test/classes/hello.hellospring.HelloSpringApplicationTests.html @@ -0,0 +1,133 @@ + + + + + +Test results - HelloSpringApplicationTests + + + + + +
+

HelloSpringApplicationTests

+ +
+ + + + + +
+
+ + + + + + + +
+
+
1
+

tests

+
+
+
+
0
+

failures

+
+
+
+
0
+

ignored

+
+
+
+
1.135s
+

duration

+
+
+
+
+
+
100%
+

successful

+
+
+
+
+ +
+

Tests

+ + + + + + + + + + + + + +
TestDurationResult
contextLoads()1.135spassed
+
+
+

Standard output

+ +
18:58:20.184 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [hello.hellospring.HelloSpringApplicationTests]: HelloSpringApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
+18:58:20.330 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration hello.hellospring.HelloSpringApplication for test class hello.hellospring.HelloSpringApplicationTests
+
+  .   ____          _            __ _ _
+ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
+( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
+ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
+  '  |____| .__|_| |_|_| |_\__, | / / / /
+ =========|_|==============|___/=/_/_/_/
+ :: Spring Boot ::                (v3.2.4)
+
+2024-03-31T18:58:20.896+09:00  INFO 49541 --- [hello-spring] [    Test worker] h.h.HelloSpringApplicationTests          : Starting HelloSpringApplicationTests using Java 21.0.2 with PID 49541 (started by ichan-uadmin in /Users/ichan-uadmin/Desktop/Spring/hello-spring)
+2024-03-31T18:58:20.899+09:00  INFO 49541 --- [hello-spring] [    Test worker] h.h.HelloSpringApplicationTests          : No active profile set, falling back to 1 default profile: "default"
+2024-03-31T18:58:22.266+09:00  INFO 49541 --- [hello-spring] [    Test worker] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
+2024-03-31T18:58:22.650+09:00  INFO 49541 --- [hello-spring] [    Test worker] h.h.HelloSpringApplicationTests          : Started HelloSpringApplicationTests in 2.105 seconds (process running for 3.945)
+
+
+
+
+

Standard error

+ +
WARNING: A Java agent has been loaded dynamically (/Users/ichan-uadmin/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.14.12/be4984cb6fd1ef1d11f218a648889dfda44b8a15/byte-buddy-agent-1.14.12.jar)
+WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
+WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
+WARNING: Dynamic loading of agents will be disallowed by default in a future release
+
+
+
+
+ +
+ + diff --git a/chan0831/hello-spring/build/reports/tests/test/css/base-style.css b/chan0831/hello-spring/build/reports/tests/test/css/base-style.css new file mode 100644 index 00000000..4afa73e3 --- /dev/null +++ b/chan0831/hello-spring/build/reports/tests/test/css/base-style.css @@ -0,0 +1,179 @@ + +body { + margin: 0; + padding: 0; + font-family: sans-serif; + font-size: 12pt; +} + +body, a, a:visited { + color: #303030; +} + +#content { + padding-left: 50px; + padding-right: 50px; + padding-top: 30px; + padding-bottom: 30px; +} + +#content h1 { + font-size: 160%; + margin-bottom: 10px; +} + +#footer { + margin-top: 100px; + font-size: 80%; + white-space: nowrap; +} + +#footer, #footer a { + color: #a0a0a0; +} + +#line-wrapping-toggle { + vertical-align: middle; +} + +#label-for-line-wrapping-toggle { + vertical-align: middle; +} + +ul { + margin-left: 0; +} + +h1, h2, h3 { + white-space: nowrap; +} + +h2 { + font-size: 120%; +} + +ul.tabLinks { + padding-left: 0; + padding-top: 10px; + padding-bottom: 10px; + overflow: auto; + min-width: 800px; + width: auto !important; + width: 800px; +} + +ul.tabLinks li { + float: left; + height: 100%; + list-style: none; + padding-left: 10px; + padding-right: 10px; + padding-top: 5px; + padding-bottom: 5px; + margin-bottom: 0; + -moz-border-radius: 7px; + border-radius: 7px; + margin-right: 25px; + border: solid 1px #d4d4d4; + background-color: #f0f0f0; +} + +ul.tabLinks li:hover { + background-color: #fafafa; +} + +ul.tabLinks li.selected { + background-color: #c5f0f5; + border-color: #c5f0f5; +} + +ul.tabLinks a { + font-size: 120%; + display: block; + outline: none; + text-decoration: none; + margin: 0; + padding: 0; +} + +ul.tabLinks li h2 { + margin: 0; + padding: 0; +} + +div.tab { +} + +div.selected { + display: block; +} + +div.deselected { + display: none; +} + +div.tab table { + min-width: 350px; + width: auto !important; + width: 350px; + border-collapse: collapse; +} + +div.tab th, div.tab table { + border-bottom: solid #d0d0d0 1px; +} + +div.tab th { + text-align: left; + white-space: nowrap; + padding-left: 6em; +} + +div.tab th:first-child { + padding-left: 0; +} + +div.tab td { + white-space: nowrap; + padding-left: 6em; + padding-top: 5px; + padding-bottom: 5px; +} + +div.tab td:first-child { + padding-left: 0; +} + +div.tab td.numeric, div.tab th.numeric { + text-align: right; +} + +span.code { + display: inline-block; + margin-top: 0em; + margin-bottom: 1em; +} + +span.code pre { + font-size: 11pt; + padding-top: 10px; + padding-bottom: 10px; + padding-left: 10px; + padding-right: 10px; + margin: 0; + background-color: #f7f7f7; + border: solid 1px #d0d0d0; + min-width: 700px; + width: auto !important; + width: 700px; +} + +span.wrapped pre { + word-wrap: break-word; + white-space: pre-wrap; + word-break: break-all; +} + +label.hidden { + display: none; +} \ No newline at end of file diff --git a/chan0831/hello-spring/build/reports/tests/test/css/style.css b/chan0831/hello-spring/build/reports/tests/test/css/style.css new file mode 100644 index 00000000..3dc4913e --- /dev/null +++ b/chan0831/hello-spring/build/reports/tests/test/css/style.css @@ -0,0 +1,84 @@ + +#summary { + margin-top: 30px; + margin-bottom: 40px; +} + +#summary table { + border-collapse: collapse; +} + +#summary td { + vertical-align: top; +} + +.breadcrumbs, .breadcrumbs a { + color: #606060; +} + +.infoBox { + width: 110px; + padding-top: 15px; + padding-bottom: 15px; + text-align: center; +} + +.infoBox p { + margin: 0; +} + +.counter, .percent { + font-size: 120%; + font-weight: bold; + margin-bottom: 8px; +} + +#duration { + width: 125px; +} + +#successRate, .summaryGroup { + border: solid 2px #d0d0d0; + -moz-border-radius: 10px; + border-radius: 10px; +} + +#successRate { + width: 140px; + margin-left: 35px; +} + +#successRate .percent { + font-size: 180%; +} + +.success, .success a { + color: #008000; +} + +div.success, #successRate.success { + background-color: #bbd9bb; + border-color: #008000; +} + +.failures, .failures a { + color: #b60808; +} + +.skipped, .skipped a { + color: #c09853; +} + +div.failures, #successRate.failures { + background-color: #ecdada; + border-color: #b60808; +} + +ul.linkList { + padding-left: 0; +} + +ul.linkList li { + list-style: none; + margin-bottom: 5px; +} diff --git a/chan0831/hello-spring/build/reports/tests/test/index.html b/chan0831/hello-spring/build/reports/tests/test/index.html new file mode 100644 index 00000000..03b13e3c --- /dev/null +++ b/chan0831/hello-spring/build/reports/tests/test/index.html @@ -0,0 +1,133 @@ + + + + + +Test results - Test Summary + + + + + +
+

Test Summary

+
+ + + + + +
+
+ + + + + + + +
+
+
1
+

tests

+
+
+
+
0
+

failures

+
+
+
+
0
+

ignored

+
+
+
+
1.135s
+

duration

+
+
+
+
+
+
100%
+

successful

+
+
+
+
+ +
+

Packages

+ + + + + + + + + + + + + + + + + + + + + +
PackageTestsFailuresIgnoredDurationSuccess rate
+hello.hellospring +1001.135s100%
+
+
+

Classes

+ + + + + + + + + + + + + + + + + + + + + +
ClassTestsFailuresIgnoredDurationSuccess rate
+hello.hellospring.HelloSpringApplicationTests +1001.135s100%
+
+
+ +
+ + diff --git a/chan0831/hello-spring/build/reports/tests/test/js/report.js b/chan0831/hello-spring/build/reports/tests/test/js/report.js new file mode 100644 index 00000000..83bab4a1 --- /dev/null +++ b/chan0831/hello-spring/build/reports/tests/test/js/report.js @@ -0,0 +1,194 @@ +(function (window, document) { + "use strict"; + + var tabs = {}; + + function changeElementClass(element, classValue) { + if (element.getAttribute("className")) { + element.setAttribute("className", classValue); + } else { + element.setAttribute("class", classValue); + } + } + + function getClassAttribute(element) { + if (element.getAttribute("className")) { + return element.getAttribute("className"); + } else { + return element.getAttribute("class"); + } + } + + function addClass(element, classValue) { + changeElementClass(element, getClassAttribute(element) + " " + classValue); + } + + function removeClass(element, classValue) { + changeElementClass(element, getClassAttribute(element).replace(classValue, "")); + } + + function initTabs() { + var container = document.getElementById("tabs"); + + tabs.tabs = findTabs(container); + tabs.titles = findTitles(tabs.tabs); + tabs.headers = findHeaders(container); + tabs.select = select; + tabs.deselectAll = deselectAll; + tabs.select(0); + + return true; + } + + function getCheckBox() { + return document.getElementById("line-wrapping-toggle"); + } + + function getLabelForCheckBox() { + return document.getElementById("label-for-line-wrapping-toggle"); + } + + function findCodeBlocks() { + var spans = document.getElementById("tabs").getElementsByTagName("span"); + var codeBlocks = []; + for (var i = 0; i < spans.length; ++i) { + if (spans[i].className.indexOf("code") >= 0) { + codeBlocks.push(spans[i]); + } + } + return codeBlocks; + } + + function forAllCodeBlocks(operation) { + var codeBlocks = findCodeBlocks(); + + for (var i = 0; i < codeBlocks.length; ++i) { + operation(codeBlocks[i], "wrapped"); + } + } + + function toggleLineWrapping() { + var checkBox = getCheckBox(); + + if (checkBox.checked) { + forAllCodeBlocks(addClass); + } else { + forAllCodeBlocks(removeClass); + } + } + + function initControls() { + if (findCodeBlocks().length > 0) { + var checkBox = getCheckBox(); + var label = getLabelForCheckBox(); + + checkBox.onclick = toggleLineWrapping; + checkBox.checked = false; + + removeClass(label, "hidden"); + } + } + + function switchTab() { + var id = this.id.substr(1); + + for (var i = 0; i < tabs.tabs.length; i++) { + if (tabs.tabs[i].id === id) { + tabs.select(i); + break; + } + } + + return false; + } + + function select(i) { + this.deselectAll(); + + changeElementClass(this.tabs[i], "tab selected"); + changeElementClass(this.headers[i], "selected"); + + while (this.headers[i].firstChild) { + this.headers[i].removeChild(this.headers[i].firstChild); + } + + var h2 = document.createElement("H2"); + + h2.appendChild(document.createTextNode(this.titles[i])); + this.headers[i].appendChild(h2); + } + + function deselectAll() { + for (var i = 0; i < this.tabs.length; i++) { + changeElementClass(this.tabs[i], "tab deselected"); + changeElementClass(this.headers[i], "deselected"); + + while (this.headers[i].firstChild) { + this.headers[i].removeChild(this.headers[i].firstChild); + } + + var a = document.createElement("A"); + + a.setAttribute("id", "ltab" + i); + a.setAttribute("href", "#tab" + i); + a.onclick = switchTab; + a.appendChild(document.createTextNode(this.titles[i])); + + this.headers[i].appendChild(a); + } + } + + function findTabs(container) { + return findChildElements(container, "DIV", "tab"); + } + + function findHeaders(container) { + var owner = findChildElements(container, "UL", "tabLinks"); + return findChildElements(owner[0], "LI", null); + } + + function findTitles(tabs) { + var titles = []; + + for (var i = 0; i < tabs.length; i++) { + var tab = tabs[i]; + var header = findChildElements(tab, "H2", null)[0]; + + header.parentNode.removeChild(header); + + if (header.innerText) { + titles.push(header.innerText); + } else { + titles.push(header.textContent); + } + } + + return titles; + } + + function findChildElements(container, name, targetClass) { + var elements = []; + var children = container.childNodes; + + for (var i = 0; i < children.length; i++) { + var child = children.item(i); + + if (child.nodeType === 1 && child.nodeName === name) { + if (targetClass && child.className.indexOf(targetClass) < 0) { + continue; + } + + elements.push(child); + } + } + + return elements; + } + + // Entry point. + + window.onload = function() { + initTabs(); + initControls(); + }; +} (window, window.document)); \ No newline at end of file diff --git a/chan0831/hello-spring/build/reports/tests/test/packages/hello.hellospring.html b/chan0831/hello-spring/build/reports/tests/test/packages/hello.hellospring.html new file mode 100644 index 00000000..3fec32cb --- /dev/null +++ b/chan0831/hello-spring/build/reports/tests/test/packages/hello.hellospring.html @@ -0,0 +1,103 @@ + + + + + +Test results - Package hello.hellospring + + + + + +
+

Package hello.hellospring

+ +
+ + + + + +
+
+ + + + + + + +
+
+
1
+

tests

+
+
+
+
0
+

failures

+
+
+
+
0
+

ignored

+
+
+
+
1.135s
+

duration

+
+
+
+
+
+
100%
+

successful

+
+
+
+
+ +
+

Classes

+ + + + + + + + + + + + + + + + + + + +
ClassTestsFailuresIgnoredDurationSuccess rate
+HelloSpringApplicationTests +1001.135s100%
+
+
+ +
+ + diff --git a/chan0831/hello-spring/build/resolvedMainClassName b/chan0831/hello-spring/build/resolvedMainClassName new file mode 100644 index 00000000..ec2d0cc4 --- /dev/null +++ b/chan0831/hello-spring/build/resolvedMainClassName @@ -0,0 +1 @@ +hello.hellospring.HelloSpringApplication \ No newline at end of file diff --git a/oneeee822/hello-spring/src/main/resources/application.properties b/chan0831/hello-spring/build/resources/main/application.properties similarity index 100% rename from oneeee822/hello-spring/src/main/resources/application.properties rename to chan0831/hello-spring/build/resources/main/application.properties diff --git a/oneeee822/hello-spring/src/main/resources/static/index.html b/chan0831/hello-spring/build/resources/main/static/index.html similarity index 90% rename from oneeee822/hello-spring/src/main/resources/static/index.html rename to chan0831/hello-spring/build/resources/main/static/index.html index 9ede8887..fe624188 100644 --- a/oneeee822/hello-spring/src/main/resources/static/index.html +++ b/chan0831/hello-spring/build/resources/main/static/index.html @@ -2,11 +2,10 @@ Hello - + Hello hello - - + \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/hello.html b/chan0831/hello-spring/build/resources/main/templates/hello.html similarity index 95% rename from ajwoong/hello-spring/hello-spring/src/main/resources/templates/hello.html rename to chan0831/hello-spring/build/resources/main/templates/hello.html index 81f8f1c8..0750f58e 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/hello.html +++ b/chan0831/hello-spring/build/resources/main/templates/hello.html @@ -2,7 +2,7 @@ Hello - +

μ•ˆλ…•ν•˜μ„Έμš”. μ†λ‹˜

diff --git a/chan0831/hello-spring/build/test-results/test/TEST-hello.hellospring.HelloSpringApplicationTests.xml b/chan0831/hello-spring/build/test-results/test/TEST-hello.hellospring.HelloSpringApplicationTests.xml new file mode 100644 index 00000000..16e8001a --- /dev/null +++ b/chan0831/hello-spring/build/test-results/test/TEST-hello.hellospring.HelloSpringApplicationTests.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/chan0831/hello-spring/build/test-results/test/binary/output.bin b/chan0831/hello-spring/build/test-results/test/binary/output.bin new file mode 100644 index 00000000..2934c873 Binary files /dev/null and b/chan0831/hello-spring/build/test-results/test/binary/output.bin differ diff --git a/chan0831/hello-spring/build/test-results/test/binary/output.bin.idx b/chan0831/hello-spring/build/test-results/test/binary/output.bin.idx new file mode 100644 index 00000000..7936b694 Binary files /dev/null and b/chan0831/hello-spring/build/test-results/test/binary/output.bin.idx differ diff --git a/chan0831/hello-spring/build/test-results/test/binary/results.bin b/chan0831/hello-spring/build/test-results/test/binary/results.bin new file mode 100644 index 00000000..cecfb188 Binary files /dev/null and b/chan0831/hello-spring/build/test-results/test/binary/results.bin differ diff --git a/chan0831/hello-spring/build/tmp/bootJar/MANIFEST.MF b/chan0831/hello-spring/build/tmp/bootJar/MANIFEST.MF new file mode 100644 index 00000000..bbcffaaa --- /dev/null +++ b/chan0831/hello-spring/build/tmp/bootJar/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Main-Class: org.springframework.boot.loader.launch.JarLauncher +Start-Class: hello.hellospring.HelloSpringApplication +Spring-Boot-Version: 3.2.4 +Spring-Boot-Classes: BOOT-INF/classes/ +Spring-Boot-Lib: BOOT-INF/lib/ +Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx +Spring-Boot-Layers-Index: BOOT-INF/layers.idx +Build-Jdk-Spec: 21 +Implementation-Title: hello-spring +Implementation-Version: 0.0.1-SNAPSHOT + diff --git a/chan0831/hello-spring/build/tmp/compileJava/previous-compilation-data.bin b/chan0831/hello-spring/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 00000000..31d733b5 Binary files /dev/null and b/chan0831/hello-spring/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/chan0831/hello-spring/build/tmp/compileTestJava/previous-compilation-data.bin b/chan0831/hello-spring/build/tmp/compileTestJava/previous-compilation-data.bin new file mode 100644 index 00000000..4789d58a Binary files /dev/null and b/chan0831/hello-spring/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/chan0831/hello-spring/build/tmp/jar/MANIFEST.MF b/chan0831/hello-spring/build/tmp/jar/MANIFEST.MF new file mode 100644 index 00000000..58630c02 --- /dev/null +++ b/chan0831/hello-spring/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/chan0831/hello-spring/gradle/.idea/.gitignore b/chan0831/hello-spring/gradle/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/chan0831/hello-spring/gradle/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/UMC_7th_Spring.iml b/chan0831/hello-spring/gradle/.idea/gradle.iml similarity index 100% rename from .idea/UMC_7th_Spring.iml rename to chan0831/hello-spring/gradle/.idea/gradle.iml diff --git a/chan0831/hello-spring/gradle/.idea/libraries/gradle_wrapper.xml b/chan0831/hello-spring/gradle/.idea/libraries/gradle_wrapper.xml new file mode 100644 index 00000000..d2b3f274 --- /dev/null +++ b/chan0831/hello-spring/gradle/.idea/libraries/gradle_wrapper.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/chan0831/hello-spring/gradle/.idea/misc.xml b/chan0831/hello-spring/gradle/.idea/misc.xml new file mode 100644 index 00000000..69ace3f6 --- /dev/null +++ b/chan0831/hello-spring/gradle/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/chan0831/hello-spring/gradle/.idea/modules.xml similarity index 56% rename from .idea/modules.xml rename to chan0831/hello-spring/gradle/.idea/modules.xml index 24aa6b06..be92c07b 100644 --- a/.idea/modules.xml +++ b/chan0831/hello-spring/gradle/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/.gitignore b/chan0831/hello-spring/hello-spring/.gitignore similarity index 100% rename from ajwoong/hello-spring/hello-spring/.gitignore rename to chan0831/hello-spring/hello-spring/.gitignore diff --git a/ajwoong/hello-spring/hello-spring/build.gradle b/chan0831/hello-spring/hello-spring/build.gradle similarity index 67% rename from ajwoong/hello-spring/hello-spring/build.gradle rename to chan0831/hello-spring/hello-spring/build.gradle index d42ab997..48f6ab54 100644 --- a/ajwoong/hello-spring/hello-spring/build.gradle +++ b/chan0831/hello-spring/hello-spring/build.gradle @@ -1,16 +1,14 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.3.1' - id 'io.spring.dependency-management' version '1.1.5' + id 'org.springframework.boot' version '3.2.4' + id 'io.spring.dependency-management' version '1.1.4' } group = 'hello' version = '0.0.1-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(22) - } + sourceCompatibility = '21' } repositories { @@ -20,11 +18,16 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' + testImplementation 'org.springframework.boot:spring-boot-starter-test' //implementation 'org.springframework.boot:spring-boot-starter-jdbc' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'com.h2database:h2' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } + + + } tasks.named('test') { diff --git a/oneeee822/hello-spring/gradle/wrapper/gradle-wrapper.jar b/chan0831/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.jar similarity index 69% rename from oneeee822/hello-spring/gradle/wrapper/gradle-wrapper.jar rename to chan0831/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.jar index a4b76b95..e6441136 100644 Binary files a/oneeee822/hello-spring/gradle/wrapper/gradle-wrapper.jar and b/chan0831/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.jar differ diff --git a/oneeee822/hello-spring/gradle/wrapper/gradle-wrapper.properties b/chan0831/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.properties similarity index 93% rename from oneeee822/hello-spring/gradle/wrapper/gradle-wrapper.properties rename to chan0831/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.properties index df97d72b..b82aa23a 100644 --- a/oneeee822/hello-spring/gradle/wrapper/gradle-wrapper.properties +++ b/chan0831/hello-spring/hello-spring/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/oneeee822/hello-spring/gradlew b/chan0831/hello-spring/hello-spring/gradlew similarity index 96% rename from oneeee822/hello-spring/gradlew rename to chan0831/hello-spring/hello-spring/gradlew index f5feea6d..1aa94a42 100755 --- a/oneeee822/hello-spring/gradlew +++ b/chan0831/hello-spring/hello-spring/gradlew @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## # @@ -57,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -86,8 +84,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/oneeee822/hello-spring/gradlew.bat b/chan0831/hello-spring/hello-spring/gradlew.bat similarity index 95% rename from oneeee822/hello-spring/gradlew.bat rename to chan0831/hello-spring/hello-spring/gradlew.bat index 9b42019c..7101f8e4 100644 --- a/oneeee822/hello-spring/gradlew.bat +++ b/chan0831/hello-spring/hello-spring/gradlew.bat @@ -13,8 +13,6 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/ajwoong/hello-spring/hello-spring/settings.gradle b/chan0831/hello-spring/hello-spring/settings.gradle similarity index 100% rename from ajwoong/hello-spring/hello-spring/settings.gradle rename to chan0831/hello-spring/hello-spring/settings.gradle diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/HelloSpringApplication.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/HelloSpringApplication.java similarity index 78% rename from oneeee822/hello-spring/src/main/java/hello/hello_spring/HelloSpringApplication.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/HelloSpringApplication.java index 2b10ea22..0b9f2864 100644 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/HelloSpringApplication.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/HelloSpringApplication.java @@ -1,4 +1,4 @@ -package hello.hello_spring; +package hello.hellospring; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,7 +6,8 @@ @SpringBootApplication public class HelloSpringApplication { - public static void main(String[] args) { + public static void main(String[] args) + { SpringApplication.run(HelloSpringApplication.class, args); } diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/SpringConfig.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/SpringConfig.java similarity index 52% rename from oneeee822/hello-spring/src/main/java/hello/hello_spring/SpringConfig.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/SpringConfig.java index 2dc72844..f4473948 100644 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/SpringConfig.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/SpringConfig.java @@ -1,10 +1,10 @@ -package hello.hello_spring; - -import hello.hello_spring.repository.MemberRepository; -import hello.hello_spring.repository.MemoryMemberRepository; -import hello.hello_spring.service.MemberService; +package hello.hellospring; +import hello.hellospring.aop.TimeTraceAop; +import hello.hellospring.repository.*; +import hello.hellospring.service.MemberService; import org.springframework.context.annotation.Bean; - +import org.springframework.context.annotation.Configuration; +@Configuration public class SpringConfig { private final MemberRepository memberRepository; public SpringConfig(MemberRepository memberRepository) { @@ -14,4 +14,9 @@ public SpringConfig(MemberRepository memberRepository) { public MemberService memberService() { return new MemberService(memberRepository); } -} + +// @Bean +// public TimeTraceAop timeTraceAop(){ +// return new TimeTraceAop(); +// } +} \ No newline at end of file diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/aop/TimeTraceAop.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/aop/TimeTraceAop.java similarity index 74% rename from oneeee822/hello-spring/src/main/java/hello/hello_spring/aop/TimeTraceAop.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/aop/TimeTraceAop.java index a01b2972..ab7a29b3 100644 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/aop/TimeTraceAop.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/aop/TimeTraceAop.java @@ -1,23 +1,24 @@ package hello.hellospring.aop; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; -@Component + @Aspect +@Component public class TimeTraceAop { @Around("execution(* hello.hellospring..*(..))") - public Object execute(ProceedingJoinPoint joinPoint) throws Throwable { + public Object execute(ProceedingJoinPoint joinPoint) throws Throwable{ long start = System.currentTimeMillis(); - System.out.println("START: " + joinPoint.toString()); - try { + System.out.println("START : " + joinPoint.toString()); + try{ return joinPoint.proceed(); - } finally { + }finally{ long finish = System.currentTimeMillis(); long timeMs = finish - start; - System.out.println("END: " + joinPoint.toString() + " " + timeMs + "ms"); + System.out.println("END :"+joinPoint.toString() +" " + timeMs + "ms"); } } - -} \ No newline at end of file +} diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/HelloController.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/HelloController.java similarity index 69% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/HelloController.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/HelloController.java index 41129594..a1fc1b02 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/HelloController.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/HelloController.java @@ -1,8 +1,8 @@ -package hello.hello_spring.controller; +package hello.hellospring.controller; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @@ -10,24 +10,23 @@ public class HelloController { @GetMapping("hello") - public String hello(Model model) { - model.addAttribute("data", "spring!!"); + public String hello(Model model){ + model.addAttribute("data","hello!!"); return "hello"; } - @GetMapping("hello-mvc") - public String helloMvc(@RequestParam(value = "name") String name, Model model){ - model.addAttribute("name", name); + @GetMapping("hell-mvc") + public String helloMvc(@RequestParam("name")String name, Model model){ + model.addAttribute("name",name); return "hello-template"; } @GetMapping("hello-string") @ResponseBody - public String helloString(@RequestParam(value = "name") String name){ + public String helloString(@RequestParam("name") String name){ return "hello" + name; } - @GetMapping("hello-api") @ResponseBody public Hello helloApi(@RequestParam("name") String name){ @@ -35,8 +34,7 @@ public Hello helloApi(@RequestParam("name") String name){ hello.setName(name); return hello; } - - static class Hello { + static class Hello{ private String name; public String getName() { @@ -47,5 +45,4 @@ public void setName(String name) { this.name = name; } } - } diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/HomeController.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/HomeController.java similarity index 82% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/HomeController.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/HomeController.java index 20bc2543..f3b1739f 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/HomeController.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/HomeController.java @@ -1,4 +1,4 @@ -package hello.hello_spring.controller; +package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -9,8 +9,5 @@ public class HomeController { @GetMapping("/") public String home(){ return "home"; - } - - - + }; } diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/MemberController.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/MemberController.java similarity index 76% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/MemberController.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/MemberController.java index 1f1f7c99..21297706 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/MemberController.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/MemberController.java @@ -1,10 +1,9 @@ -package hello.hello_spring.controller; +package hello.hellospring.controller; -import hello.hello_spring.domain.Member; -import hello.hello_spring.service.MemberService; +import hello.hellospring.domain.Member; +import hello.hellospring.service.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.stereotype.Service; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -21,7 +20,8 @@ public MemberController(MemberService memberService) { } @GetMapping("/members/new") - public String createForm() { + public String createForm(){ + return "members/createMemberForm"; } @@ -36,10 +36,9 @@ public String create(MemberForm form){ } @GetMapping("/members") - public String list(Model model){ + public String list(Model model){ List members = memberService.findMembers(); - model.addAttribute("members", members); + model.addAttribute("members",members); return "members/memberList"; } - } diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/MemberForm.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/MemberForm.java similarity index 51% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/MemberForm.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/MemberForm.java index 26064e98..a5c753a5 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/controller/MemberForm.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/controller/MemberForm.java @@ -1,13 +1,13 @@ -package hello.hello_spring.controller; +package hello.hellospring.controller; public class MemberForm { private String name; - public String getName() { + public String getName(){ return name; } - public void setName(String name) { + public void setName(String name){ this.name = name; } } diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/domain/Member.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/domain/Member.java similarity index 77% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/domain/Member.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/domain/Member.java index f20083e3..b46ab212 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/domain/Member.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/domain/Member.java @@ -1,4 +1,4 @@ -package hello.hello_spring.domain; +package hello.hellospring.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -6,25 +6,21 @@ import jakarta.persistence.Id; @Entity -public class Member { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) +public class Member { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - private String name; - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getName() { + return name; } - public void setName(String name) { this.name = name; - } -} + } } \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JdbcMemberRepository.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JdbcMemberRepository.java similarity index 95% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JdbcMemberRepository.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JdbcMemberRepository.java index d1bb33e0..a562ae70 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JdbcMemberRepository.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JdbcMemberRepository.java @@ -1,6 +1,6 @@ -package hello.hello_spring.repository; +package hello.hellospring.repository; -import hello.hello_spring.domain.Member; +import hello.hellospring.domain.Member; import org.springframework.jdbc.datasource.DataSourceUtils; import javax.sql.DataSource; @@ -9,12 +9,16 @@ import java.util.List; import java.util.Optional; +import static java.sql.DriverManager.getConnection; + public class JdbcMemberRepository implements MemberRepository{ private final DataSource dataSource; - public JdbcMemberRepository(DataSource dataSource) { + + public JdbcMemberRepository(DataSource dataSource){ this.dataSource = dataSource; } + @Override public Member save(Member member) { String sql = "insert into member(name) values(?)"; @@ -39,6 +43,7 @@ public Member save(Member member) { close(conn, pstmt, rs); } } + @Override public Optional findById(Long id) { String sql = "select * from member where id = ?"; @@ -62,8 +67,7 @@ public Optional findById(Long id) { throw new IllegalStateException(e); } finally { close(conn, pstmt, rs); - } - } + } } @Override public List findAll() { String sql = "select * from member"; @@ -76,6 +80,7 @@ public List findAll() { rs = pstmt.executeQuery(); List members = new ArrayList<>(); while(rs.next()) { + Member member = new Member(); member.setId(rs.getLong("id")); member.setName(rs.getString("name")); @@ -112,6 +117,7 @@ public Optional findByName(String name) { close(conn, pstmt, rs); } } + private Connection getConnection() { return DataSourceUtils.getConnection(dataSource); } @@ -141,5 +147,4 @@ private void close(Connection conn, PreparedStatement pstmt, ResultSet rs) { private void close(Connection conn) throws SQLException { DataSourceUtils.releaseConnection(conn, dataSource); } -} - +} \ No newline at end of file diff --git a/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JdbcTemplateMemberRepository.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JdbcTemplateMemberRepository.java new file mode 100644 index 00000000..0c03439e --- /dev/null +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JdbcTemplateMemberRepository.java @@ -0,0 +1,53 @@ +package hello.hellospring.repository; + +import hello.hellospring.domain.Member; +import hello.hellospring.repository.MemberRepository; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; +import javax.sql.DataSource; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +public class JdbcTemplateMemberRepository implements MemberRepository { + private final JdbcTemplate jdbcTemplate; + public JdbcTemplateMemberRepository(DataSource dataSource) { + jdbcTemplate = new JdbcTemplate(dataSource); + } + @Override + public Member save(Member member) { + SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(jdbcTemplate); + jdbcInsert.withTableName("member").usingGeneratedKeyColumns("id"); + Map parameters = new HashMap<>(); + parameters.put("name", member.getName()); + Number key = jdbcInsert.executeAndReturnKey(new + MapSqlParameterSource(parameters)); + member.setId(key.longValue()); + return member; + } + @Override + public Optional findById(Long id) { + List result = jdbcTemplate.query("select * from member where id = ?", memberRowMapper(), id); + return result.stream().findAny(); + } + @Override + public List findAll() { + return jdbcTemplate.query("select * from member", memberRowMapper()); + } + @Override + public Optional findByName(String name) { + List result = jdbcTemplate.query("select * from member wherename = ?", memberRowMapper(), name); + return result.stream().findAny(); + } + private RowMapper memberRowMapper() { + return (rs, rowNum) -> { + Member member = new Member(); + member.setId(rs.getLong("id")); + member.setName(rs.getString("name")); + return member; + }; } +} \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JpaMemberRepository.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JpaMemberRepository.java similarity index 58% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JpaMemberRepository.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JpaMemberRepository.java index cfeefaea..1d49e1a7 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/JpaMemberRepository.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/JpaMemberRepository.java @@ -1,21 +1,18 @@ -package hello.hello_spring.repository; +package hello.hellospring.repository; -import hello.hello_spring.domain.Member; +import hello.hellospring.domain.Member; import jakarta.persistence.EntityManager; -import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; -@Transactional public class JpaMemberRepository implements MemberRepository{ private final EntityManager em; - public JpaMemberRepository(EntityManager em) { + public JpaMemberRepository(EntityManager em){ this.em = em; } - @Override public Member save(Member member) { em.persist(member); @@ -24,22 +21,24 @@ public Member save(Member member) { @Override public Optional findById(Long id) { - Member member = em.find(Member.class, id); + Member member = em.find(Member.class,id); return Optional.ofNullable(member); } @Override public Optional findByName(String name) { - List result = em.createQuery("select m from Member m where m.name = :name", Member.class) - .setParameter("name", name) + List result = em.createQuery("select m from Member m where m.name=:name", Member.class) + .setParameter("name",name) .getResultList(); + return result.stream().findAny(); } @Override public List findAll() { - List result = em.createQuery("select m from Member m", Member.class) + return em.createQuery("select m from Member m", Member.class) .getResultList(); - return result; + //Member 객체λ₯Ό λŒ€μƒμœΌλ‘œ (μ—”ν‹°ν‹°λ₯Ό λŒ€μƒμœΌλ‘œ) 쿼리λ₯Ό 날리고 id, name 등을 선택할 ν•„μš” 없이 + //객체 κ·Έ 자체λ₯Ό μ…€λ ‰νŠΈν•΄μ€€λ‹€. 이미 맀핑이 λ‹€ λ˜μ–΄μžˆμŒ. } } diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/MemberRepository.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/MemberRepository.java similarity index 64% rename from oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/MemberRepository.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/MemberRepository.java index 6ce8aac3..93b53280 100644 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/MemberRepository.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/MemberRepository.java @@ -1,10 +1,11 @@ -package hello.hello_spring.repository; - -import hello.hello_spring.domain.Member; +package hello.hellospring.repository; +import hello.hellospring.domain.Member; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; + public interface MemberRepository { Member save(Member member); Optional findById(Long id); diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/MemoryMemberRepository.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/MemoryMemberRepository.java similarity index 70% rename from oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/MemoryMemberRepository.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/MemoryMemberRepository.java index 790f74ee..10646c8b 100644 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/MemoryMemberRepository.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/MemoryMemberRepository.java @@ -1,16 +1,15 @@ -package hello.hello_spring.repository; +package hello.hellospring.repository; -import hello.hello_spring.domain.Member; +import hello.hellospring.domain.Member; import org.springframework.stereotype.Repository; import java.util.*; -public class MemoryMemberRepository implements MemberRepository { +public class MemoryMemberRepository implements MemberRepository{ private static Map store = new HashMap<>(); private static long sequence = 0L; - @Override public Member save(Member member) { member.setId(++sequence); @@ -20,13 +19,13 @@ public Member save(Member member) { @Override public Optional findById(Long id) { - return Optional.ofNullable(store.get(id)); + return Optional.ofNullable(store.get(id)); } @Override public Optional findByName(String name) { return store.values().stream() - .filter(m -> m.getName().equals(name)) + .filter(member -> member.getName().equals(name) ) .findAny(); } @@ -36,7 +35,6 @@ public List findAll() { } public void clearStore(){ - store.clear(); + store.clear(); } } - diff --git a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/SpringDataJpaMemberRepository.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/SpringDataJpaMemberRepository.java similarity index 59% rename from ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/SpringDataJpaMemberRepository.java rename to chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/SpringDataJpaMemberRepository.java index 6c88cc4d..498b6c2f 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/java/hello/hello_spring/repository/SpringDataJpaMemberRepository.java +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/repository/SpringDataJpaMemberRepository.java @@ -1,11 +1,8 @@ -package hello.hello_spring.repository; - -import hello.hello_spring.domain.Member; +package hello.hellospring.repository; +import hello.hellospring.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; - import java.util.Optional; - -public interface SpringDataJpaMemberRepository extends JpaRepository, MemberRepository{ - @Override +public interface SpringDataJpaMemberRepository extends JpaRepository, MemberRepository { Optional findByName(String name); } diff --git a/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/service/MemberService.java b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/service/MemberService.java new file mode 100644 index 00000000..336a2e56 --- /dev/null +++ b/chan0831/hello-spring/hello-spring/src/main/java/hello/hellospring/service/MemberService.java @@ -0,0 +1,63 @@ +package hello.hellospring.service; + +import hello.hellospring.domain.Member; +import hello.hellospring.repository.MemberRepository; +//import hello.hellospring.repository.MemoryMemberRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; + +@Transactional +public class MemberService { + + + private final MemberRepository memberRepository ; + + public MemberService(MemberRepository memberRepository){ + this.memberRepository = memberRepository; + } + /* + νšŒμ›κ°€μž… + + */ + + public Long join(Member member){ + +// long start = System.currentTimeMillis(); +// +// try{ +// validateDuplicateMember(member); +// memberRepository.save(member); +// return member.getId(); +// } finally { +// long finish = System.currentTimeMillis(); +// long timeMs = finish - start; +// System.out.println("join = " + timeMs + "ms"); +// } + + //같은 이름이 μžˆλŠ” 경우 μ•ˆλœλ‹€κ³  ν•˜μž + validateDuplicateMember(member); + + memberRepository.save(member); + return member.getId(); + } + + private void validateDuplicateMember(Member member) { + memberRepository.findByName(member.getName()) + .ifPresent(m->{ + throw new IllegalStateException(("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€.")); + }); + } + + public List findMembers(){ + return memberRepository.findAll(); + + } + + public Optional findOne(Long memberId){ + return memberRepository.findById(memberId); + } +} diff --git a/chan0831/hello-spring/hello-spring/src/main/resources/application.properties b/chan0831/hello-spring/hello-spring/src/main/resources/application.properties new file mode 100644 index 00000000..c32737ec --- /dev/null +++ b/chan0831/hello-spring/hello-spring/src/main/resources/application.properties @@ -0,0 +1,7 @@ + + +spring.datasource.url=jdbc:h2:tcp://localhost/~/test +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.username=sa +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto=none \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/static/hello-static.html b/chan0831/hello-spring/hello-spring/src/main/resources/static/hello-static.html similarity index 83% rename from ajwoong/hello-spring/hello-spring/src/main/resources/static/hello-static.html rename to chan0831/hello-spring/hello-spring/src/main/resources/static/hello-static.html index 68254b2a..ace36d98 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/static/hello-static.html +++ b/chan0831/hello-spring/hello-spring/src/main/resources/static/hello-static.html @@ -2,9 +2,10 @@ static content - + 정적 컨텐츠 μž…λ‹ˆλ‹€. +hello \ No newline at end of file diff --git a/chan0831/hello-spring/hello-spring/src/main/resources/static/index.html b/chan0831/hello-spring/hello-spring/src/main/resources/static/index.html new file mode 100644 index 00000000..fe624188 --- /dev/null +++ b/chan0831/hello-spring/hello-spring/src/main/resources/static/index.html @@ -0,0 +1,11 @@ + + + + Hello + + + +Hello +hello + + \ No newline at end of file diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/hello-template.html b/chan0831/hello-spring/hello-spring/src/main/resources/templates/hello-template.html similarity index 100% rename from ajwoong/hello-spring/hello-spring/src/main/resources/templates/hello-template.html rename to chan0831/hello-spring/hello-spring/src/main/resources/templates/hello-template.html diff --git a/oneeee822/hello-spring/src/main/resources/templates/hello.html b/chan0831/hello-spring/hello-spring/src/main/resources/templates/hello.html similarity index 62% rename from oneeee822/hello-spring/src/main/resources/templates/hello.html rename to chan0831/hello-spring/hello-spring/src/main/resources/templates/hello.html index da4fc92b..0750f58e 100644 --- a/oneeee822/hello-spring/src/main/resources/templates/hello.html +++ b/chan0831/hello-spring/hello-spring/src/main/resources/templates/hello.html @@ -1,9 +1,8 @@ - - Hello - + Hello +

μ•ˆλ…•ν•˜μ„Έμš”. μ†λ‹˜

diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/home.html b/chan0831/hello-spring/hello-spring/src/main/resources/templates/home.html similarity index 81% rename from ajwoong/hello-spring/hello-spring/src/main/resources/templates/home.html rename to chan0831/hello-spring/hello-spring/src/main/resources/templates/home.html index 109d59d7..554cef70 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/home.html +++ b/chan0831/hello-spring/hello-spring/src/main/resources/templates/home.html @@ -1,7 +1,7 @@ + -

Hello Spring

νšŒμ› κΈ°λŠ₯

@@ -9,7 +9,7 @@

Hello Spring

νšŒμ› κ°€μž… νšŒμ› λͺ©λ‘

-
-
+ + \ No newline at end of file diff --git a/oneeee822/hello-spring/src/main/resources/templates/members/createMemberForm.html b/chan0831/hello-spring/hello-spring/src/main/resources/templates/members/createMemberForm.html similarity index 74% rename from oneeee822/hello-spring/src/main/resources/templates/members/createMemberForm.html rename to chan0831/hello-spring/hello-spring/src/main/resources/templates/members/createMemberForm.html index 6f4fb441..9fb73314 100644 --- a/oneeee822/hello-spring/src/main/resources/templates/members/createMemberForm.html +++ b/chan0831/hello-spring/hello-spring/src/main/resources/templates/members/createMemberForm.html @@ -1,14 +1,16 @@ - + +
-
-
-
+ + + + - \ No newline at end of file + diff --git a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/members/memberList.html b/chan0831/hello-spring/hello-spring/src/main/resources/templates/members/memberList.html similarity index 91% rename from ajwoong/hello-spring/hello-spring/src/main/resources/templates/members/memberList.html rename to chan0831/hello-spring/hello-spring/src/main/resources/templates/members/memberList.html index 31aaf5e6..2550af21 100644 --- a/ajwoong/hello-spring/hello-spring/src/main/resources/templates/members/memberList.html +++ b/chan0831/hello-spring/hello-spring/src/main/resources/templates/members/memberList.html @@ -1,5 +1,6 @@ - + +
@@ -18,6 +19,7 @@
-
+ + \ No newline at end of file diff --git a/oneeee822/hello-spring/src/test/java/hello/hello_spring/HelloSpringApplicationTests.java b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/HelloSpringApplicationTests.java similarity index 86% rename from oneeee822/hello-spring/src/test/java/hello/hello_spring/HelloSpringApplicationTests.java rename to chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/HelloSpringApplicationTests.java index 4b93a19b..87d37cfd 100644 --- a/oneeee822/hello-spring/src/test/java/hello/hello_spring/HelloSpringApplicationTests.java +++ b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/HelloSpringApplicationTests.java @@ -1,4 +1,4 @@ -package hello.hello_spring; +package hello.hellospring; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/oneeee822/hello-spring/src/test/java/hello/hello_spring/repository/MemoryMemberRepositoryTest.java b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/repository/MemoryMemberRepositoryTest.java similarity index 66% rename from oneeee822/hello-spring/src/test/java/hello/hello_spring/repository/MemoryMemberRepositoryTest.java rename to chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/repository/MemoryMemberRepositoryTest.java index 22cf5558..0c5ecfd7 100644 --- a/oneeee822/hello-spring/src/test/java/hello/hello_spring/repository/MemoryMemberRepositoryTest.java +++ b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/repository/MemoryMemberRepositoryTest.java @@ -1,35 +1,34 @@ -package hello.hello_spring.repository; +package hello.hellospring.repository; -import hello.hello_spring.domain.Member; +import hello.hellospring.domain.Member; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import java.util.List; - -import static org.assertj.core.api.Assertions.*; +import java.util.Optional; public class MemoryMemberRepositoryTest { - MemoryMemberRepository repository = new MemoryMemberRepository(); + MemoryMemberRepository repository = new MemoryMemberRepository(); @AfterEach - public void afterEach() { + public void afterEach(){ repository.clearStore(); } - @Test - public void save() { + public void save(){ Member member = new Member(); member.setName("spring"); repository.save(member); - Member result = repository.findById(member.getId()).get(); - assertThat(member).isEqualTo(result); + Member result = repository.findById((member.getId())).get(); + //Assertions.assertEquals(member , result); + Assertions.assertThat(member).isEqualTo(result); } @Test - public void findByName() { + public void findByName(){ Member member1 = new Member(); member1.setName("spring1"); repository.save(member1); @@ -40,11 +39,11 @@ public void findByName() { Member result = repository.findByName("spring1").get(); - assertThat(result).isEqualTo(member1); + Assertions.assertThat(result).isEqualTo(member1); } @Test - public void findAll() { + public void findAll(){ Member member1 = new Member(); member1.setName("spring1"); repository.save(member1); @@ -54,7 +53,6 @@ public void findAll() { repository.save(member2); List result = repository.findAll(); - assertThat(result.size()).isEqualTo(2); - + Assertions.assertThat(result.size()).isEqualTo(2); } } diff --git a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceIntegrationTest.java b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/service/MemberServiceIntegrationTest.java similarity index 78% rename from ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceIntegrationTest.java rename to chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/service/MemberServiceIntegrationTest.java index 71d6ae49..74609e9f 100644 --- a/ajwoong/hello-spring/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceIntegrationTest.java +++ b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/service/MemberServiceIntegrationTest.java @@ -1,29 +1,26 @@ -package hello.hello_spring.service; -import hello.hello_spring.domain.Member; -import hello.hello_spring.repository.MemberRepository; +package hello.hellospring.service; +import hello.hellospring.domain.Member; +import hello.hellospring.repository.MemberRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Commit; import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @SpringBootTest @Transactional - class MemberServiceIntegrationTest { @Autowired MemberService memberService; @Autowired MemberRepository memberRepository; - @Test public void νšŒμ›κ°€μž…() throws Exception { //Given Member member = new Member(); - member.setName("hispring"); + member.setName("hello"); //When Long saveId = memberService.join(member); -//Then + //Then Member findMember = memberRepository.findById(saveId).get(); assertEquals(member.getName(), findMember.getName()); } @@ -37,7 +34,5 @@ class MemberServiceIntegrationTest { //When memberService.join(member1); IllegalStateException e = assertThrows(IllegalStateException.class, - () -> memberService.join(member2));//μ˜ˆμ™Έκ°€ λ°œμƒν•΄μ•Ό ν•œλ‹€. - assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); - } -} \ No newline at end of file + () -> memberService.join(member2));//μ˜ˆμ™Έκ°€ λ°œμƒν•΄μ•Ό ν•œλ‹€. assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); + } } \ No newline at end of file diff --git a/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/service/MemberServiceTest.java b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/service/MemberServiceTest.java new file mode 100644 index 00000000..874ffad1 --- /dev/null +++ b/chan0831/hello-spring/hello-spring/src/test/java/hello/hellospring/service/MemberServiceTest.java @@ -0,0 +1,71 @@ +package hello.hellospring.service; + +import hello.hellospring.domain.Member; +import hello.hellospring.repository.MemoryMemberRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class MemberServiceTest { + MemberService memberService ; + MemoryMemberRepository memberRepository = new MemoryMemberRepository(); + + @BeforeEach + public void beforeEach(){ + memberRepository = new MemoryMemberRepository(); + memberService = new MemberService(memberRepository); + + } + @AfterEach + public void afterEach(){ + memberRepository.clearStore(); + } + @Test + void νšŒμ›κ°€μž…() { + //given + Member member = new Member(); + member.setName("hello"); + //when + Long saveId = memberService.join(member); + //then + Member findMember = memberService.findOne(saveId).get(); + Assertions.assertThat(member.getName()).isEqualTo(findMember.getName()); + } + + @Test + public void 쀑볡_νšŒμ›_μ˜ˆμ™Έ(){ + //given + Member member1 = new Member(); + member1.setName("spring1"); + + Member member2 = new Member(); + member2.setName("spring1"); + + //when + memberService.join(member1); + IllegalStateException e = assertThrows(IllegalStateException.class, () -> memberService.join(member2)); + + Assertions.assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); + + /* + try{ + memberService.join(member2); + fail("μ˜ˆμ™Έκ°€ λ°œμƒν•΄μ•Ό ν•©λ‹ˆλ‹€."); + }catch(IllegalStateException e){ + Assertions.assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); + } + */ + + } + + @Test + void findMembers() { + } + + @Test + void findOne() { + } +} \ No newline at end of file diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/HelloSpringApplication.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/HelloSpringApplication.class new file mode 100644 index 00000000..d2bc86ac Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/HelloSpringApplication.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/SpringConfig.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/SpringConfig.class new file mode 100644 index 00000000..65cbe9a7 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/SpringConfig.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/aop/TimeTraceAop.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/aop/TimeTraceAop.class new file mode 100644 index 00000000..b7316373 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/aop/TimeTraceAop.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HelloController$Hello.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HelloController$Hello.class new file mode 100644 index 00000000..8c5bf3c2 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HelloController$Hello.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HelloController.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HelloController.class new file mode 100644 index 00000000..efdd2f30 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HelloController.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HomeController.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HomeController.class new file mode 100644 index 00000000..1f0b0299 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/HomeController.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/MemberController.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/MemberController.class new file mode 100644 index 00000000..a4373185 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/MemberController.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/MemberForm.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/MemberForm.class new file mode 100644 index 00000000..ca9ec1dd Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/controller/MemberForm.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/domain/Member.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/domain/Member.class new file mode 100644 index 00000000..3d7b6ec0 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/domain/Member.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JdbcMemberRepository.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JdbcMemberRepository.class new file mode 100644 index 00000000..d3eed408 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JdbcMemberRepository.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JdbcTemplateMemberRepository.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JdbcTemplateMemberRepository.class new file mode 100644 index 00000000..dcfe44ee Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JdbcTemplateMemberRepository.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JpaMemberRepository.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JpaMemberRepository.class new file mode 100644 index 00000000..cdf6ceb8 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/JpaMemberRepository.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/MemberRepository.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/MemberRepository.class new file mode 100644 index 00000000..4805557b Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/MemberRepository.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/MemoryMemberRepository.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/MemoryMemberRepository.class new file mode 100644 index 00000000..7fd7116b Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/MemoryMemberRepository.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/SpringDataJpaMemberRepository.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/SpringDataJpaMemberRepository.class new file mode 100644 index 00000000..6471811d Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/repository/SpringDataJpaMemberRepository.class differ diff --git a/chan0831/hello-spring/out/production/classes/hello/hellospring/service/MemberService.class b/chan0831/hello-spring/out/production/classes/hello/hellospring/service/MemberService.class new file mode 100644 index 00000000..ddd6b483 Binary files /dev/null and b/chan0831/hello-spring/out/production/classes/hello/hellospring/service/MemberService.class differ diff --git a/chan0831/hello-spring/out/production/resources/application.properties b/chan0831/hello-spring/out/production/resources/application.properties new file mode 100644 index 00000000..c32737ec --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/application.properties @@ -0,0 +1,7 @@ + + +spring.datasource.url=jdbc:h2:tcp://localhost/~/test +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.username=sa +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto=none \ No newline at end of file diff --git a/chan0831/hello-spring/out/production/resources/static/hello-static.html b/chan0831/hello-spring/out/production/resources/static/hello-static.html new file mode 100644 index 00000000..ace36d98 --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/static/hello-static.html @@ -0,0 +1,11 @@ + + + + static content + + + +정적 컨텐츠 μž…λ‹ˆλ‹€. +hello + + \ No newline at end of file diff --git a/chan0831/hello-spring/out/production/resources/static/index.html b/chan0831/hello-spring/out/production/resources/static/index.html new file mode 100644 index 00000000..fe624188 --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/static/index.html @@ -0,0 +1,11 @@ + + + + Hello + + + +Hello +hello + + \ No newline at end of file diff --git a/oneeee822/hello-spring/src/main/resources/templates/hello-template.html b/chan0831/hello-spring/out/production/resources/templates/hello-template.html similarity index 100% rename from oneeee822/hello-spring/src/main/resources/templates/hello-template.html rename to chan0831/hello-spring/out/production/resources/templates/hello-template.html diff --git a/chan0831/hello-spring/out/production/resources/templates/hello.html b/chan0831/hello-spring/out/production/resources/templates/hello.html new file mode 100644 index 00000000..0750f58e --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/templates/hello.html @@ -0,0 +1,10 @@ + + + + Hello + + + +

μ•ˆλ…•ν•˜μ„Έμš”. μ†λ‹˜

+ + \ No newline at end of file diff --git a/chan0831/hello-spring/out/production/resources/templates/home.html b/chan0831/hello-spring/out/production/resources/templates/home.html new file mode 100644 index 00000000..554cef70 --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/templates/home.html @@ -0,0 +1,15 @@ + + + + +
+

Hello Spring

+

νšŒμ› κΈ°λŠ₯

+

+ νšŒμ› κ°€μž… + νšŒμ› λͺ©λ‘ +

+
+ + + \ No newline at end of file diff --git a/chan0831/hello-spring/out/production/resources/templates/members/createMemberForm.html b/chan0831/hello-spring/out/production/resources/templates/members/createMemberForm.html new file mode 100644 index 00000000..9fb73314 --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/templates/members/createMemberForm.html @@ -0,0 +1,16 @@ + + + + +
+
+
+ + +
+ +
+
+ + + diff --git a/chan0831/hello-spring/out/production/resources/templates/members/memberList.html b/chan0831/hello-spring/out/production/resources/templates/members/memberList.html new file mode 100644 index 00000000..2550af21 --- /dev/null +++ b/chan0831/hello-spring/out/production/resources/templates/members/memberList.html @@ -0,0 +1,25 @@ + + + + +
+
+ + + + + + + + + + + + + +
#이름
+
+
+ + + \ No newline at end of file diff --git a/chan0831/hello-spring/out/test/classes/hello/hellospring/HelloSpringApplicationTests.class b/chan0831/hello-spring/out/test/classes/hello/hellospring/HelloSpringApplicationTests.class new file mode 100644 index 00000000..57e95e02 Binary files /dev/null and b/chan0831/hello-spring/out/test/classes/hello/hellospring/HelloSpringApplicationTests.class differ diff --git a/chan0831/hello-spring/out/test/classes/hello/hellospring/repository/MemoryMemberRepositoryTest.class b/chan0831/hello-spring/out/test/classes/hello/hellospring/repository/MemoryMemberRepositoryTest.class new file mode 100644 index 00000000..e256782f Binary files /dev/null and b/chan0831/hello-spring/out/test/classes/hello/hellospring/repository/MemoryMemberRepositoryTest.class differ diff --git a/chan0831/hello-spring/out/test/classes/hello/hellospring/service/MemberServiceIntegrationTest.class b/chan0831/hello-spring/out/test/classes/hello/hellospring/service/MemberServiceIntegrationTest.class new file mode 100644 index 00000000..58db12ba Binary files /dev/null and b/chan0831/hello-spring/out/test/classes/hello/hellospring/service/MemberServiceIntegrationTest.class differ diff --git a/chan0831/hello-spring/out/test/classes/hello/hellospring/service/MemberServiceTest.class b/chan0831/hello-spring/out/test/classes/hello/hellospring/service/MemberServiceTest.class new file mode 100644 index 00000000..d7159549 Binary files /dev/null and b/chan0831/hello-spring/out/test/classes/hello/hellospring/service/MemberServiceTest.class differ diff --git a/oneeee822/.DS_Store b/oneeee822/.DS_Store deleted file mode 100644 index 016ad188..00000000 Binary files a/oneeee822/.DS_Store and /dev/null differ diff --git a/oneeee822/hello-spring/.DS_Store b/oneeee822/hello-spring/.DS_Store deleted file mode 100644 index 98dccb0d..00000000 Binary files a/oneeee822/hello-spring/.DS_Store and /dev/null differ diff --git a/oneeee822/hello-spring/build.gradle b/oneeee822/hello-spring/build.gradle deleted file mode 100644 index 1e56aa37..00000000 --- a/oneeee822/hello-spring/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id 'java' - id 'org.springframework.boot' version '3.3.4' - id 'io.spring.dependency-management' version '1.1.6' -} - -group = 'hello' -version = '0.0.1-SNAPSHOT' - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } -} - -repositories { - mavenCentral() -} - -dependencies { - implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' - implementation 'org.springframework.boot:spring-boot-starter-web' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' -} - -tasks.named('test') { - useJUnitPlatform() -} diff --git a/oneeee822/hello-spring/settings.gradle b/oneeee822/hello-spring/settings.gradle deleted file mode 100644 index 69a39da7..00000000 --- a/oneeee822/hello-spring/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'hello-spring' diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/HelloController.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/HelloController.java deleted file mode 100644 index 283c5591..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/HelloController.java +++ /dev/null @@ -1,53 +0,0 @@ -package hello.hello_spring.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class HelloController { - - @GetMapping("hello") - public String hello(Model model) { - model.addAttribute("data", "hello!!"); - return "hello"; - } - - @GetMapping("hello-mvc") - public String helloMvc(@RequestParam("name") String name, Model model) { - model.addAttribute("name", name); - return "hello-template"; - } - - //데이터 κ·ΈλŒ€λ‘œ λ³΄μ—¬μ€Œ. ν…œν”Œλ¦Ώ λ³€ν™˜X - @GetMapping("hello-string") - @ResponseBody - public String helloString(@RequestParam("name") String name) { - return "hello " + name; - - } - - //객체 λ°˜ν™˜ - @GetMapping("hello-api") - @ResponseBody - public Hello helloApi(@RequestParam("name") String name) { - Hello hello = new Hello(); - hello.setName(name); - return hello; - } - - static class Hello{ - private String name; - - public String getName(){ - return name; - } - - public void setName(String name) { - this.name = name; - } - } - -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/HomeController.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/HomeController.java deleted file mode 100644 index cb0c9571..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/HomeController.java +++ /dev/null @@ -1,10 +0,0 @@ -package hello.hello_spring.controller; - -import org.springframework.web.bind.annotation.GetMapping; - -public class HomeController { - @GetMapping("/") - public String home() { - return "home"; - } -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/MemberController.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/MemberController.java deleted file mode 100644 index d8db25c8..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/MemberController.java +++ /dev/null @@ -1,42 +0,0 @@ -package hello.hello_spring.controller; - -import hello.hello_spring.domain.Member; -import hello.hello_spring.service.MemberService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; - -import java.util.List; - -@Controller -public class MemberController { - - private final MemberService memberService; - - @Autowired - public MemberController(MemberService memberService) { - this.memberService = memberService; - } - - @GetMapping(value = "/members/new") - public String createForm() { - return "members/createMemberForm"; - } - - @PostMapping(value = "/members/new") - public String create(MemberForm form) { - Member member = new Member(); - member.setName(form.getName()); - memberService.join(member); - return "redirect:/"; - } - - @GetMapping(value = "/members") - public String list(Model model) { - List members = memberService.findMembers(); - model.addAttribute("members", members); - return "members/memberList"; - } -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/MemberForm.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/MemberForm.java deleted file mode 100644 index a061d0aa..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/controller/MemberForm.java +++ /dev/null @@ -1,11 +0,0 @@ -package hello.hello_spring.controller; - -public class MemberForm { - private String name; - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/domain/Member.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/domain/Member.java deleted file mode 100644 index b070603c..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/domain/Member.java +++ /dev/null @@ -1,22 +0,0 @@ -package hello.hello_spring.domain; - -public class Member { - private Long id; - private String name; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/JpaRepository.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/JpaRepository.java deleted file mode 100644 index 7e50c876..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/JpaRepository.java +++ /dev/null @@ -1,4 +0,0 @@ -package hello.hello_spring.repository; - -public interface JpaRepository { -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/SpringDataJpaMemberRepository.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/SpringDataJpaMemberRepository.java deleted file mode 100644 index af0333b0..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/repository/SpringDataJpaMemberRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package hello.hello_spring.repository; - -import hello.hello_spring.domain.Member; - -import java.util.Optional; - -public interface SpringDataJpaMemberRepository extends JpaRepository, MemberRepository { - Optional findByName(String name); -} diff --git a/oneeee822/hello-spring/src/main/java/hello/hello_spring/service/MemberService.java b/oneeee822/hello-spring/src/main/java/hello/hello_spring/service/MemberService.java deleted file mode 100644 index 31965988..00000000 --- a/oneeee822/hello-spring/src/main/java/hello/hello_spring/service/MemberService.java +++ /dev/null @@ -1,46 +0,0 @@ -package hello.hello_spring.service; - -import hello.hello_spring.domain.Member; -import hello.hello_spring.repository.MemberRepository; -import hello.hello_spring.repository.MemoryMemberRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; - -public class MemberService { - - private final MemberRepository memberRepository; - - public MemberService(MemberRepository memberRepository) { - this.memberRepository = memberRepository; - } - - /** - * νšŒμ› κ°€μž… - */ - public Long join(Member member) { - //같은 이름이 μžˆλŠ” 쀑볡 νšŒμ› X - validateDuplicateMember(member); - return memberRepository.save(member).getId(); - } - - private void validateDuplicateMember(Member member) { - memberRepository.findByName(member.getName()) - .ifPresent(m -> { - throw new IllegalStateException("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); - }); - } - - /** - * 전체 νšŒμ› 쑰회 - */ - public List findMembers() { - return memberRepository.findAll(); - } - - public Optional findOne(Long memberId) { - return memberRepository.findById(memberId); - } -} diff --git a/oneeee822/hello-spring/src/main/resources/templates/home.html b/oneeee822/hello-spring/src/main/resources/templates/home.html deleted file mode 100644 index 50c52416..00000000 --- a/oneeee822/hello-spring/src/main/resources/templates/home.html +++ /dev/null @@ -1,14 +0,0 @@ - - - -
-
-

Hello Spring

νšŒμ› κΈ°λŠ₯

-

- νšŒμ› κ°€μž… - νšŒμ› λͺ©λ‘

- -
-
- - diff --git a/oneeee822/hello-spring/src/main/resources/templates/members/memberList.html b/oneeee822/hello-spring/src/main/resources/templates/members/memberList.html deleted file mode 100644 index b81b78bd..00000000 --- a/oneeee822/hello-spring/src/main/resources/templates/members/memberList.html +++ /dev/null @@ -1,22 +0,0 @@ - - - -
-
- - - - - - - - - - - - -
#이름
-
-
- - \ No newline at end of file diff --git a/oneeee822/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceTest.java b/oneeee822/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceTest.java deleted file mode 100644 index 0fe00e6f..00000000 --- a/oneeee822/hello-spring/src/test/java/hello/hello_spring/service/MemberServiceTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package hello.hello_spring.service; - -import hello.hello_spring.domain.Member; -import hello.hello_spring.repository.MemoryMemberRepository; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class MemberServiceTest { - - MemberService memberService; - MemoryMemberRepository memoryMemberRepository; - - @BeforeEach - public void beforeEach() { - memoryMemberRepository = new MemoryMemberRepository(); - memberService = new MemberService(memoryMemberRepository); - } - @AfterEach - public void afterEach() { - memoryMemberRepository.clearStore(); - } - - @Test - void νšŒμ›κ°€μž…() { - //given - Member member = new Member(); - member.setName("hello"); - - //when - Long saveId = memberService.join(member); - - //then - Member findMember = memberService.findOne(saveId).get(); - assertThat(member.getName()).isEqualsTo(findMember().getName()); - } - - @Test - public void 쀑볡_νšŒμ›_μ˜ˆμ™Έ() { - Member member1 = new Member(); - member1.setName("spring"); - - Member member2 = new Member(); - member2.setName("spring2"); - - memberService.join(member1); - IllegalStateException e = Assertions.assertThrows(IllegalStateException.class, () -> memberService.join(member2)); - assertThat(e.getMessage()).isEqualTo("이미 μ‘΄μž¬ν•˜λŠ” νšŒμ›μž…λ‹ˆλ‹€."); - } - - @Test - void findMembers() { - } - - @Test - void findOne() { - } -} \ No newline at end of file