Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD : Category Controller/Entity/Repository #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/shopping/jpa/controller/CategoryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.shopping.jpa.controller;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Controller
@Transactional
public class CategoryController {
@PersistenceContext
EntityManager entityManager;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EntityManager 를 직접 호출해서 사용하는 일은 없을 것 같아요. 바로 서비스가 호출 될 것 같아요.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정답이라고 할 수는 없겠지만 controller layer에서 data persist를 처리하는 것보다 service layer를 하나 더 두는 게 좋은 것 같습니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CategoryRepository 를 EntityManager 대신 사용하면 되지 않을까 싶습니다!


//TODO : CRUD
}
4 changes: 0 additions & 4 deletions src/main/java/com/shopping/jpa/controller/TempController.java

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/java/com/shopping/jpa/model/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.shopping.jpa.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Category {
@Id
@GeneratedValue
private Long id;

@Column
private String categoryName;
}
4 changes: 0 additions & 4 deletions src/main/java/com/shopping/jpa/model/TempModel.java

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/java/com/shopping/jpa/repository/CategoryRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.shopping.jpa.repository;


import com.shopping.jpa.model.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JpaRepository 를 상속받으면 구현체가 org.springframework.data.jpa.repository.support.SimpleJpaRepository 로 만들어져서 이미 @Repository 를 가지게 됩니다. 그래서 여기다가 중복해서 명시하지 않아도 된대요.

interface CategoryRepository extends JpaRepository<Category, Long> {
}
4 changes: 0 additions & 4 deletions src/main/java/com/shopping/jpa/repository/TempRepository.java

This file was deleted.