Skip to content

ADD : Category Controller/Entity/Repository#2

Open
junhee-ko wants to merge 1 commit intodevelopfrom
feature/category
Open

ADD : Category Controller/Entity/Repository#2
junhee-ko wants to merge 1 commit intodevelopfrom
feature/category

Conversation

@junhee-ko
Copy link
Contributor

No description provided.

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 를 가지게 됩니다. 그래서 여기다가 중복해서 명시하지 않아도 된대요.

@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 대신 사용하면 되지 않을까 싶습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants