λ°μν
νμ μ ν Enum ν΄λμ€
- νμμ μ ν(Admin, User)λ₯Ό λνλ΄λ μμκ°
νμ ν΄λμ€
package com.example.yunishop.domain.member;
import com.example.yunishop.constant.Role;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
@Getter
@NoArgsConstructor
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String memberId;
private String password;
private int postCode;
private String address;
private String addtionalAddress;
private Role role;
}
Entity κ΄λ ¨ Annotation
μ΄λ Έν μ΄μ | μ€λͺ |
---|---|
@Entity | ν΄λμ€λ₯Ό μν°ν°λ‘ μ μΈ |
@Id | ν μ΄λΈμ κΈ°λ³Έν€μ μ¬μ©ν μμ±μ μ§μ |
@GeneratedValue | ν€ κ°μ μμ±νλ μ λ΅ λͺ μ |
νμ ν μ΄λΈ μμ±
νμ Repository μ€κ³
package com.example.yunishop.domain.member;
import org.springframework.data.jpa.repository.JpaRepository;
public interface MemberRepository extends JpaRepository<Member, Long> {
}
ν μ€νΈλ₯Ό μν application-test.properties μμ±
# Datasource μ€μ
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.username=sa
spring.datasource.password=
# H2 λ°μ΄ν°λ² μ΄μ€ λ°©μΈ μ€μ
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
νμ μ μ₯ ν μ€νΈ
@SpringBootTest
@TestPropertySource(locations = "classpath:application-test.properties")
class MemberRepositoryTest {
@Autowired
MemberRepository memberRepository;
@Test
void νμ_μ μ₯_ν
μ€νΈ() {
Member member = new Member();
member.setName("ν
μ€νΈ");
member.setMemberId("ν
μ€νΈ");
member.setPassword("ν
μ€νΈ");
member.setPostCode(111);
member.setAddress("ν
μ€νΈ");
member.setAddtionalAddress("ν
μ€νΈ");
Member savedMember = memberRepository.save(member);
System.out.println(savedMember.toString());
}
}
Annotation | μ€λͺ |
---|---|
@SpringBootTest | ν΅ν© ν μ€νΈλ₯Ό μν΄ μ€νλ§ λΆνΈμμ μ 곡νλ μ λ Έν μ΄μ . μ€μ μ ν리μΌμ΄μ μ ꡬλν λμ²λΌ λͺ¨λ Beanμ IoC 컨ν μ΄λμ λ±λ‘ |
@TestPropertySource | ν μ€νΈ μ½λ μ€ν μ, application.propertiesμ μ€μ ν΄λ κ°λ³΄λ€, locationμ μ€μ λ κ°μ λ λμ μ°μ μμλ₯Ό λΆμ¬ |
728x90
λ°μν
'μ€νλ§ > μΌνλͺ° νλ‘μ νΈ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
νμκ°μ κΈ°λ₯ ꡬν (0) | 2022.11.22 |
---|---|
λΉλ ν¨ν΄ (0) | 2022.11.21 |
μ€νλ§ μν리ν°λ₯Ό μ΄μ©ν λ‘κ·ΈμΈ/λ‘κ·Έμμ (0) | 2022.11.21 |
Thymeleaf - κ³΅ν΅ λ μ΄μμ (0) | 2022.11.21 |
JPA (1) | 2022.11.21 |