목록2024/07/21 (4)
wintertreey 님의 블로그
프로젝트 생성시 dependencies 세팅 이번엔 Spring Data JPA를 추가해주었다. 테이블 만들기 application.properties# JPA Hibernate settingspring.jpa.hibernate.ddl-auto=update기존에없던 테이블을 새로만들어줄때 적는 세팅코드. update는 기존유지. create하면 기존테이블을 drop하고 새로만듦. ProductVo.javapackage pack.model;import jakarta.persistence.Column;import jakarta.persistence.Entity;import jakarta.persistence.GeneratedValue;import jakarta.persistence.GenerationTy..
스프링 데이터 JPA : CrudRepositorySpring Data JDBC 라이브러리는 CrudRepository 인터페이스를 제공한다.CrudRepository는 스프링 데이터 JPA에서 제공하는 기본 CRUD (Create, Read, Update, Delete) 작업을 처리하기 위한 인터페이스이다. CrudRepository는 엔티티 객체의 기본적인 데이터 조작을 간단하게 수행할 수 있도록 설계되어 있다. 다음은 CrudRepository의 주요 메소드 질문 : CrudRepository는 인터페이스인데, 예를 들어 count() 추상 메소드의 경우 count에 대한 재정의를 한 적이 없는데 어떻게 결과가 나오는 걸까? CrudRepository는 스프링 데이터 JPA에서 기본 CRUD 작..
mybatis의장점 클래스와 sql문의 분리. 유지보수가 편하다. Datamapininter.java데이터연동을위한 어노테이션걸어준다. package pack.model;import java.util.List;import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Select;import pack.controller.FormBean;@Mapperpublic interface DataMappingInter { @Select("select * from sangdata") List selectAll(); @Select("select code, sang, su, dan from sangdata where sang li..
JdbcDaoSupport를 이용해 db연동 Constructor Injection. why? 이건 (가상의) 필드주입 코드.@Repositorypublic class DataDao extends JdbcDaoSupport { @Autowired private DataSource dataSource; 생성자 주입의 가장 큰 장점이 불변성을 보장한다는점이다. 생성자주입은 객체 생성 시점에 의존성을 주입하므로, "DataSource"와 같은 의존성을 final로 선언할 수 있다. 이로인해 객체의 상태를 보장할 수 있게 된다. 그 이외에도 테스트용이성, 명확한 의존성 명세등의 장점이 있다. 필드 주입의 경우 다음과 같은 문제점이 발생할 수 있다. Testability: 필드 주입은 DataSou..