当前位置:网站首页>@Controller, @service, @repository, @component differences

@Controller, @service, @repository, @component differences

2022-07-06 10:45:00 Programmer seven seven

1、@controller controller ( Injection service 、 Use in Controller layer )

Used to label the control layer , amount to struts Medium action layer

2、@service service ( Inject dao、 Use in Service layer )

For tagging the service layer , It is mainly used for business logic processing

3、@repository( Realization dao visit 、 Use in Mapper layer )

Used to label data access layer , It can also be used to label data access components , namely DAO Components .

4、@component ( Put ordinary pojo Instantiate to spring In the container , Equivalent to the configuration file )

It refers to all kinds of components , That is to say, when our classes do not belong to various categories ( Do not belong to @Controller、@Services When waiting ), We can use @Component To label this class .

explain :

<context:component-scan base-package=”com.*”>
The example above is the introduction of Component Examples of components , among base-package Represents all subpackages that need to be scanned .
Common ground : By @controller 、@service、@repository 、@component Annotated classes , These classes will be included in spring Manage in containers

原网站

版权声明
本文为[Programmer seven seven]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060911410530.html