Spring55 [TIL] 231219 Spring @JoinColumn @OnDelete @ManyToOne @JoinColumn (name = "user_id") @OnDelete(action = OnDeleteAction.SET_NULL) private User user; Comment (댓글)과 User을 JoinColumn으로 연결했다. @OnDelete 여기서 @OnDelelete는 연관된 엔티티(User)이 삭제될 경우 어떻게 처리할건지 정해준다 OnDeleteAction.SET_NULL은 연관된 엔티티가 삭제될 경우 FK를 NULL로 처리한다는 뜻이다 위 코드에서는 User이 삭제될 경우 Comment를 작성한 사람이 NULL이 된다 2023. 12. 19. [TIL] 231219 Timestamped null값 에러 Post 클래스에 Timestamped를 상속 받았는데 created_at과 modifed_at에 null이 뜬다.... 그것은 바로 메인 application 클래스에 @EnableJpaAuditing이 빠져있었기 때문!!! 이렇게 추가해주면!!! 드디어!!! Timestamped의 created_at과 modified_at이 뜹니다!!!!! 2023. 12. 19. [TIL] 231215 Spring ResponseEntityList.forEach List 형태를 List로 바꾸는 방법!!! public List getAllPosts() { List postResponseDtoList = new ArrayList(); List list = postRepository.findAll(); list.forEach(post -> { var postDto = new PostResponseDto(post); postResponseDtoList.add(postDto); }); return postResponseDtoList; } for each사용하여 포스트 별로 Dto에 넣어서 만들어놓은 Dto리스트에 넣는다!!! 최고!!!!!👍👍👍👍 2023. 12. 15. [TIL] 231214 ResponseEntity @PostMapping("/signup") public ResponseEntity signup(@Valid @RequestBody UserRequestDto userRequestDto){ userService.signup(userRequestDto); return ResponseEntity.status(201).body(new CommonResponseDto("회원가입 성공",201)); } ResponseEntity 구조 - HttpStatus - HttpHeader : 요청 요구사항 - HttpBody : 내용 상태코드만 반환해줄 때 return ResponseEntity.ok().build(); 2023. 12. 14. [TIL] 231213 스프링 입문 | 김영한 인프런 https://www.youtube.com/playlist?list=PLumVmq_uRGHgBrimIp2-7MCnoPUskVMnd 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 인프런 전체 강의(무료): https://bit.ly/hellospring 재생 목록: https://www.youtube.com/playlist?list=PLumVmq_uRGHgBrimIp2-7MCnoPUs... www.youtube.com MVC : Model Controller View Controller (java파일)과 View(html)을 나눠서 구현하는 것 API : Json방식으로 구현 @ResponseBody를 사용.. 2023. 12. 13. [TIL] 231212 Spring CRUD 만들기 복습 C : create R : read U : update D : delete Create @PostMapping @RequestBody로 받아옴 Read @GetMapping @RequestParam (uri 통해서 value 받아옴) @PathVariable(uri 통해서 내용 받아옴) Update @PutMapping / @PatchMapping @RequestBody @PathVariable Delete @DeleteMapping @PathVariable 2023. 12. 12. 이전 1 ··· 3 4 5 6 7 8 9 10 다음