本文档说明常见的 Java 组件类型及其特点,帮助正确识别和注释不同类型的组件。
controller 或 web 包下Controller 结尾@RestController 或 @Controller 注解UserControllerOrderControllerProductControllerservice 包下Service 结尾service.impl 包下ServiceImpl 结尾@Service 注解UserService / UserServiceImplOrderService / OrderServiceImplmapper 或 dao 包下Mapper 或 Dao 结尾@Mapper 注解UserMapperOrderMapperProductMapperentity 或 model 包下UserOrderProductdto 包下DTO 结尾UserDTOOrderDTOUserCreateRequestUserUpdateRequestvo 包下VO 结尾UserVOOrderVObo 包下BO 结尾UserBOOrderBOrepository 包下Repository 结尾JpaRepository 或 CrudRepositoryUserRepositoryOrderRepositoryconfig 包下Config 结尾@Configuration 注解WebConfigSecurityConfigDatabaseConfigcomponent 或 util 包下@Component 注解EmailComponentFileComponentutil 或 utils 包下Util 或 Utils 结尾StringUtilDateUtilJsonUtilexception 包下Exception 结尾Exception 或 RuntimeExceptionBusinessExceptionResourceNotFoundExceptionValidationExceptioncontroller / web → Controllerservice → Serviceservice.impl → ServiceImplmapper / dao → Mapperentity / model → Entitydto → DTOvo → VObo → BOrepository → Repositoryconfig → Configurationcomponent / util → Component / Utilityexception → Exception*Controller → Controller*Service → Service*ServiceImpl → ServiceImpl*Mapper / *Dao → Mapper*DTO → DTO*VO → VO*BO → BO*Repository → Repository*Config → Configuration*Util / *Utils → Utility*Exception → Exception@RestController / @Controller → Controller@Service → Service@Mapper → Mapper@Entity → Entity@Repository → Repository@Configuration → Configuration@Component → Component根据组件类型,注释的优先级: