Model - View - Controller 구조를 기반으로
비즈니스 로직, 화면 처리, 요청 처리를 분리하여 효율적으로 웹 애플리케이션을 만드는 아키텍처
com.example.project
├── controller → 요청 처리 담당 (@Controller)
├── service → 비즈니스 로직 처리 (@Service)
├── repository → DB 접근 (DAO) (@Repository, Mapper)
├── domain → VO / DTO / Entity
├── mapper → MyBatis SQL 인터페이스 (@Mapper)
├── config → 설정 파일 (DB, MVC 등)
└── resources
├── static → 정적 자원 (CSS, JS)
├── templates → 화면 템플릿 (JSP, Thymeleaf 등)
└── mapper → MyBatis XML 매퍼 파일
계층 | 예시 클래스 | 역할 |
---|---|---|
Controller | UserController |
HTTP 요청 처리, 서비스 호출 |
Service | UserService |
비즈니스 로직 처리 |
Repository (DAO) | UserMapper , UserRepository |
DB 접근 |
Domain | User.java |
데이터 전달 객체 (VO, DTO 등) |
View | user.html , user.jsp |
사용자에게 보여줄 화면 템플릿 |
[클라이언트 요청: /users/1]
↓
@Controller (UserController)
↓
@Service (UserService)
↓
@Repository (UserMapper)
↓
[DB 조회 → 결과 객체 반환]
↓
[Service에서 가공]
↓
[Controller에서 Model에 담음]
↓
[ViewResolver → View 렌더링 (JSP, HTML)]
↓
[브라우저에 최종 응답]
public class User {
private Long id;
private String name;
}
@Mapper
public interface UserMapper {
User selectById(Long id);
}