zoukankan      html  css  js  c++  java
  • SpringAnnotation注解之@Component,@Repository,@Service,@Controller

    @Component:组件,表示此写上了此注解的bean,作为一个组件存在于容器中。这样的话别的地方就可以使用@Resource这个注解来把这个组件作为一个资源来使用了。初始化bean的名字为类名首字母小写

    与@Component注解功能相同的注解有:@Repository,@Service,@Controller,@Component ,默认情况下Spring认为这4个注解会被认为是一个组件。

    @Repository:数据层,一般放在Dao接口的实现类上

    @Service:服务层,一般放在service接口的实现类

    @Controller:控制层,一般放在action上

    例如:

    1、配置包扫描器:

    <context:component-scan base-package="com.fz.annotation"></context:component-scan>

    2、Controller层

    @Controller

    public class UserController

    3、Service层

    @Service("userService")

    public class UserService 

    4、Dao层

    @Repository

    public class UserDaoImpl implements UserDao

    其中@Controller,@Component,@Service这些注解,如果默认括号里直接写("userService")的时候表示是value=

    例如:@Service("userService") 和 @Service(value="userService") 是相等的









  • 相关阅读:
    解决VMwave下卡死的办法
    深度探索C++对象模型第四章:函数语义学
    cc
    tbb库的使用
    10内核同步方法
    哈希
    django 和restful framework 初始配置轻松搞定
    linux有趣动画--代码雨
    linux有趣开机图标--佛祖保佑
    Socket是什么,通俗易懂点说
  • 原文地址:https://www.cnblogs.com/meet/p/4758208.html
Copyright © 2011-2022 走看看