Spring/Spring boot icia 73일차

Spring/Spring boot icia 73일차

Spring boot Pk,FK 참조관계 맺기

Entity에서 테이블을 생성하는데 PK , FK으로 엮는 코드를 살펴봤다. 게시판에서 글에는 pk로 id가 있을 것이고 그 글의 첨부파일은 글의 id를 fk로 가지고 있을 것이다. package com.icia.board.entity; import lombok.Cleanup; import lombok.Data; import javax.persistence.*; @Data @Entity @Table(name = "board_file_table") public class BoardFileEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column private String originalFileName; @..

Spring/Spring boot icia 73일차

Spring boot interceptor(인터셉터)

1. interceptor ( 인터셉터 ) 란 ? 클라이언트의 요청과 응답을 가로채고 처리하는 미들웨어 역할을 한다. interceptor는 특정 URL 패턴에 대해 요청 전처리 , 후처리 , 응답 전처리 , 응답 후처리 등의 작업을 수행할 수 있다. Interceptor를 구현하기 위해서는 HandlerInterceptor 인터페이스를 구현하고 해당 인터페이스의 메소드를 오버라이딩하여 원하는 작업을 구현하면 된다. Spring이 제공하는 기술로 , 디스패처 서블릿( Dispatcher Servlet ) 이 컨트롤러를 호출하기 전과 후에 요청과 응답을 참조하거나 가공할 수 있는 기능을 제공한다. 즉 , 웹 컨테이너 ( 서블릿 컨테이너 ) 에서 동작하는 필터와 달리 인터셉터는 스프링 컨텍스트에서 동작하는 ..

Spring/Spring boot icia 73일차

Spring boot 날짜 , builder , Modifying

1. Spring boot에서의 날짜 필드 선언 @CreationTimestamp @Column(updatable = false) private LocalDateTime createdAt; @CreationTimestamp 어노테이션은 Entity의 생성 시간을 자동으로 설정해 주는 어노테이션이다. java.util.Date 타입이나 java.time.LocalDateTime 타입에 사용하는데 본문에서는 LocalDataTime 타입을 사용하였다. Updatable = false 속성은 Column을 insert할 때만 값이 적용된다는 속성이다. 2. Builder Builder 패턴을 사용하면 객체 생성 시 필드의 순서를 신경쓰지 않고 명시적으로 필드 값을 설정할 수 있으며 선택적인 필드 값을 설정하지..

Spring/Spring boot icia 73일차

Spring boot 게시판 단일파일 , 다중파일 처리

1-1. WebConfig.java package com.icia.board.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebConfig implements WebMvcConfigurer { private String resourcePath = "/upload/**"; // html 에서 접근할 경로..

Spring/Spring boot icia 73일차

Spring boot 게시판 수정 , 삭제

목록 수정 삭제 확인 수정 , 삭제가 같은 비밀번호 창을 요구하고 누른 것에 따라 매개변수를 받아서 다른 메소드를 호출하는 방식으로 수정, 삭제가 되도록 했다. @PutMapping("/{id}") public ResponseEntity update(@RequestBody BoardDTO boardDTO) { boardService.update(boardDTO); return new ResponseEntity(HttpStatus.OK); } 수정한 내용을 @RequestBody 를 이용해 boardDTO로 받아서 id값을 추가해서 save를 이용해서 업데이트를 했다. @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable Long id) {..

swkn
'Spring/Spring boot icia 73일차' 카테고리의 글 목록