minlog
article thumbnail
[ JPA ] 영속성 컨텍스트와 Entity 생애주기
BackEnd/Security · JPA 2023. 3. 29. 23:26

1. 영속성 컨텍스트 > Entity 객체를 특별하게 감시하고 관리해주는 컨테이너 영속성 컨텐스트란 엔티티를 영구 저장하는 환경이라는 뜻이다. 애플리케이션과 데이터베이스 사이에서 객체를 보관하는 가상의 데이터베이스 같은 역할을 한다. 엔티티 매니저를 통해 엔티티를 저장하거나 조회하면 엔티티 매니저는 영속성 컨텍스트에 엔티티를 보관하고 관리한다. 영속성 캐쉬가 flash가 되서 DB에 반영 되는 시점 flash() 메서드를 명시적으로 호출하는 시점 트랜직션이 끝나서 해당 쿼리가 커밋되는 시점 복잡한 조회 조건의 jpk가 실행되는 시점 2. Entity 생명 주기 'Entity' 하나의 객체에는 4가지의 상태가 존재한다. 비영속상태(new/transient) , 영속상태 (managed), 준영속상태(det..

article thumbnail
[ Spring Boot ] Thymeleaf
BackEnd/Spring Boot 2023. 3. 25. 16:39

Thymeleaf 순수 html 파일을 웹 브라우저에서 열어 내용 확인이 가능하다. 뷰 템플릿을 거치면 동적으로 변경된 결과를 확인 할 수 있다. 순수한 html을 유지하면서 동적 템플도 사용할 수 있는 타임리프의 특징을 네츄럴 템플릿이라고한다. 💡템플릿 설정 📑 build.gradle implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 스프링 부트가 자동으로 ThymeleafViewResolver 와 필요한 스프링 빈들을 등록한다. 그리고 다음 설정도 사용한다. 이 설정은 기본 값 이기 때문에 변경이 필요할 때만 설정하면 된다. 📑 application.properties spring.thymeleaf.prefix=classp..

article thumbnail
[ Spring Boot ] Exception 예외 처리 방법
BackEnd/Spring Boot 2023. 3. 10. 14:42

Exception 에러페이지 1) 4XX Error or 5XX Error 2) Client 가 200 외에 처리를 하지 못할때는 200을 내려주고 별도 메시지를 전달 Annotation 설명 @ControllerAdvice Global 예외 처리 및 특정 package/Controller 예외처리 @ExcptionHandler 특정 Controller의 예외처리 1. 글로벌한 예외를 잡는 방법 @RestControllerAdvice package com.example.exception.advice; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframew..

article thumbnail
[ Spirng ] Security - java (4) Spring-Security를 사용한 암호화
BackEnd/Spring Boot 2023. 3. 6. 17:34

Spring-Security를 사용한 암호화 1. configure(HttpSecurity http)를 오버라이딩하여 Secuirty 권한설정 추가 📑 SecurityConfig.java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter{ ... } @Override protected void configure(HttpSecurity http) throws Exception { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncodi..

article thumbnail
[ Spring ] JAVA 기반의 환경설정 방법
BackEnd/Spring Boot 2023. 3. 4. 19:38

xml > java 기반의 환경설정 1. web.xml > webConfig.java 📑 pom.xml org.apache.maven.plugins maven-war-plugin 3.2.0 false 1) web.xml 삭제시 pom.xml에 web.xml 을 사용하지 않겠다고 선언해주어야한다. 📑 webConfig.java @Override protected Class[] getRootConfigClasses() { // root-context.xml을 대신할 자바파일 연결 return return new Class[] {RootConfig.class};; } @Override protected Class[] getServletConfigClasses() { //servlet-context.xml 을 ..