μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- spring
- ToyProject
- λ°±μ€
- μ λ λμ
- OS
- ν¬λ‘€λ§
- μκ³ λ¦¬μ¦
- μμμ²λ¦¬
- matlab
- selenium
- μ΄μ§νμ
- μΌμ±κΈ°μΆ
- νλ‘κ·Έλλ¨Έμ€
- μΉ΄μΉ΄μ€κΈ°μΆ
- λ¨μν μ€νΈ
- JPA
- ν΄μλ²
- Crawling
- 그리λ
- BFS
- μ΄μ체μ
- API
- λ§€νΈλ©
- webcrawling
- μΉ΄μΉ΄μ€
- νμ΄μ¬
- ν΄μ
- μΉν¬λ‘€λ§
- python
- Java
DevKim
[02] μν λλ©μΈ κ°λ° λ³Έλ¬Έ
π ꡬν κΈ°λ₯π
1.μν λ±λ‘
2. μν λͺ©λ‘ μ‘°ν
3. μν μμ
[ μν μν°ν°μ λΉμ¦λμ€ λ‘μ§ μΆκ° ]
- μν μν°ν°μ μ£Όλ¬Έμ λ°λ₯Έ, μ¬κ³ μλμ λλ¦¬κ³ μ€μ¬λ³΄κ³ μμΈμ²λ¦¬λ₯Ό λ°μ
λλ©μΈ μ£Όλ μ€κ³μ, μν°ν° μ체μμ ν΄κ²°ν μ μλ κ²λ€μ μν°ν° μμ λΉμ¦λμ€ λ‘μ§μ λ£λκ² λ μ’κ³ ,
μμ§λκ° μκ³ κ°μ²΄μ§ν₯μ μ΄λ€.
π1. μ¬κ³ μλ μΆκ°
π2. μ¬κ³ μλ κ°μ ( μλμ΄ 0λ³΄λ€ μμ μ, μ€λ₯κ° λ°μν΄μΌνλ€ )
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "dtype")
@Getter @Setter
public class Item {
...
/**
* todo : λΉμ¦λμ€ λ‘μ§
* 1. μ¬κ³ μλ μΆκ°
* 2. μ¬κ³ μλ κ°μ (0λ³΄λ€ μμ μ, μ€λ₯ λ°μ)
*/
public void addStock(int quantity)
{
this.stockQuantity+=quantity;
}
public void removeStock(int quantity)
{
int restStock=this.stockQuantity-quantity;
if(restStock<0)
{
throw new NotEnoughStockException("need more stock");
}
this.stockQuantity=quantity;
}
}
μλμ΄ λκ°μ κ²½μ°,
μ 체 μ¬κ³ λ₯Ό λΉΌμ£Όλλ° μ΄λ λ°μνλ μμΈμ²λ¦¬λ RuntimeExceptionμ μμλ°μμ λ°λ‘ μμ±νμλ€
public class NotEnoughStockException extends RuntimeException {
public NotEnoughStockException() {
super();
}
public NotEnoughStockException(String message) {
super(message);
}
public NotEnoughStockException(String message, Throwable cause) {
super(message, cause);
}
public NotEnoughStockException(Throwable cause) {
super(cause);
}
protected NotEnoughStockException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
[ μν Repository ]
- μν λ±λ‘
- μν μ‘°ν(λ¨κ±΄,μ 체)
@Repository
@RequiredArgsConstructor
public class ItemRepository {
private final EntityManager em;
//μ μ₯
public void save(Item item) {
if (item.getId() == null) {
em.persist(item);
} else {
em.merge(item);
}
}
...
}
nullμ΄ μλλΌλ©΄, μ€μμ μνμ μν°ν°μ΄λ―λ‘ λ³ν©(merge)μ μ¬μ©νμ¬ μν°ν°λ₯Ό μμ μνλ‘ λ³κ²½νλ€.
[ μν μλΉμ€ κ°λ° ]
- μν μλΉμ€λ μν repositoryλ₯Ό λ¨μ μμλ§νλ ν΄λμ€ μ λμ΄λ€.
Todo
μν μ λ°μ΄νΈμ μλ―Έμλ λ©μλ νλ λ§λ€μ΄μ price,name..λ± νλΌλ―Έν°λ‘ λ겨μ μ λ°μ΄νΈνλ μ½λλ‘ λ¦¬ν©ν λ§
( set λλ°° X )
'Spring Boot' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[μ€νλ§ with AWS] MockMvcλ₯Ό μ΄μ©ν API ν μ€νΈ μ½λ (0) | 2021.07.10 |
---|---|
[02] μ£Όλ¬Έ λλ©μΈ κ°λ° (0) | 2021.07.08 |
[02] Entity/table μ€κ³ & νμ λλ©μΈ κ°λ° (0) | 2021.07.08 |
[02] Jpashop μ€μ΅νκΈ° μ , remind (0) | 2021.07.08 |
Controllerμ μ λ¬μΈμ μ°¨μ΄μ (0) | 2021.07.05 |