Spring 66

jpa one to many 관련

애러 발생 detached entity passed to persist: sb.lec total.hibernate Entities.oneToMany many to one 측면에서 데이터가 생성되지 않은 상태에서 one to many에 저장하거나 데이터 가 생성되기 전에 foreign key를 설정하려 하면 발생(어찌 보면 당연한...) many to one에 모든 데이터가 저장되고 난 후에 one to many에 리스트를 저장해야 함 결국 순서가 중요 * one to many가 기본으로 lazy가 설정되어 있어 @Transactional 을 해야 수행됨 (이를 피할려면 eager로 해야함) * 참고로 test에서 수행시 @Transactional을 하면 수행 후 데이터는 지워짐... 관련 코드... @E..

jpa tip

jpa에서 기본제공하는 crud를 사용하는 방법 extends 시에 적용한 class를 인식해서 동작함 findByFirstNameLikeAndLastNameOrEmailLike 등 과 같이 연속해서 사용가능 (알아서 sql 을 생성해줌) @Query 를 통해 필요한 sql을 작성 가능... @Repository public interface PersonRepository extends CrudRepository { List findByLastNameLike(String lastName); } 위와 같이 하면 @Query("from Person p where s.lastName = '%포함문자%'" 와 같은 효과가 있음 실제 사용시 List personList = personRepository.findB..

html input type

https://developer.mozilla.org/ko/docs/Web/HTML/Element/input : 입력 요소 - HTML: Hypertext Markup Language | MDN HTML 요소는 웹 기반 양식에서 사용자의 데이터를 받을 수 있는 대화형 컨트롤을 생성합니다. 사용자 에이전트에 따라서 다양한 종류의 입력 데이터 유형과 컨트롤 위젯이 존재합니다. 입 developer.mozilla.org 기본 적인 input 만 잘 사용해도 불필요한 코드를 줄이고 활용도를 높일 수 있음.... html의 form 내에서 input type이 date나 datetime-local 일때 date는 String 으로 받으면 변환이 되나, datetime-local은 @RequestParam("okn..

jsp, thymeleaf 동시에 사용하기...

application.properties 파일 설정 ### concurrent apply jsp and thymeleaf # web-inf spring-mvc... for jsp templates : web-inf/view/ 밑에 것은 jsp에서 처리 spring.mvc.view.prefix=/WEB-INF/view/ spring.mvc.view.suffix=.jsp # template for thymeleaf : default fold /resources/templates/th/ 밑에 것은 thymeleaf로 처리 spring.thymeleaf.prefix= classpath:/templates/ spring.thymeleaf.suffix= .html spring.thymeleaf.view-names=..

spring annotation

@PostConstruct bean 생성되기 전에 수행하는 annotation @Qualifier 하나의 interface에 여러게의 구현체를 구현할 경우 interface를 autowired 할때 qualifier를 사용하면 구현체를 지정할 수 있음 용도에 따라 구현체를 구분해서 각자 용도에 맞게 사용할 때 유용 할 듯 @Value("${property name}") application.properties 에 내용을 정의하고 class에서 갖다 사용할 수 있음 실제 production 할때 application.properties에 변수만 지정하고 실제 구현은 해당 시스템(linux, windows의 환경 변수에서 지정)에서 지정 할 때 유용 custom annotation 사용자 정의 annotat..

spring security DB 계정을 활용한 로그인 (spring security 6, spring boot 3.1)

어렵게 성공함 db는 postgre로 적용 build.gradle, application.properties (특이한 부분은 없음...) plugins { id 'java' id 'org.springframework.boot' version '3.1.0' id 'io.spring.dependency-management' version '1.1.0' } group = 'spring.aop' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementat..

Spring 2023.06.03

spring boot basic

start.spring.io => 프로젝트 생성 => 압축 해제 => intellij에서 불러옴 (web, thymeleaf implement) java version이 11로 되어 있어서 애러남 -> setting => gradle 설정에서 17로 변경 project setting에서 17로 변경 , 모두 통일 하면 애러 없음 기본으로 8080 포트를 열음 기본 Home page는 resources/static/intex.html 을 불러옴(localhost:8080 => 실행) controller 구성 project/controller/NameController.java 를 생성 @Controller public class HelloController { List list = new ArrayList..

Spring/spring_old 2023.05.12

11. JPA 사용을 위한 코딩

우선 db 연계를 확인... 나는 pc에 mysql을 설치하고 workbench로 db 확인 intellej ultimate에서는 application.yml 설정하면 알아서 연동할 db에 대한 연동을 확인 해줌.. 편함 1. 기존의 map 저장을 DB로 변경하기 위해 기존 mapstore를 비활성화 repository에 새로운 패키지 생성(jpo) 실제 jpa에서 사용할 entity 객체로 이 것만 있어도 db 테이블이 생성됨.. @Entity @Getter @Setter @NoArgsConstructor @Table(name = "club") // db table의 이름을 지정 가능 아니면 class 이름으로 생성 public class ClubJpo { @Id //db에서 사용할 key 값 , 반드..

Spring/spring_old 2023.01.27