zoukankan      html  css  js  c++  java
  • Spring常用注解

    1、@controller 控制器(注入服务)
    2、@service 服务(注入dao)
    3、@repository dao(实现dao访问)
    4、@component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)

    @Component:

    @定义Spring管理Bean

    
    

    @Repository:

    @Component扩展,被@Repository注解的POJO类表示DAO层实现,从而见到该注解就想到DAO层实现,使用方式和@Component相同;

    @Service:

    @Component扩展,被@Service注解的POJO类表示Service层实现,从而见到该注解就想到Service层实现,使用方式和@Component相同;

    @Controller:

    @Component扩展,被@Controller注解的类表示Web层实现,从而见到该注解就想到Web层实现,使用方式和@Component相同;

    
    
    
    
    @Component,@Service,@Controller,@Repository注解的类,并把这些类纳入进spring容器中管理。 
    下面写这个是引入component的扫描组件 
    <context:component-scan base-package=”com.mmnc”>    

    其中base-package为需要扫描的包(含所有子包) 
           1、@Service用于标注业务层组件 
           2、@Controller用于标注控制层组件(如struts中的action) 
           3、@Repository用于标注数据访问组件,即DAO组件. 
           4、@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。    
               @Service 

    public class UserServiceImpl implements UserService { } 
    @Repository 
    public class UserDaoImpl implements UserDao { } getBean的默认名称是类名(头字母小写),如果想自定义,可以@Service(“***”) 这样来指定,这种bean默认是单例的,如果想改变,可以使用@Service(“beanName”) 
    @Scope(“prototype”)来改变。可以使用以下方式指定初始化方法和销毁方法(方法名任意): @PostConstruct public void init() { } 
  • 相关阅读:
    【生活美好】H5Resume
    【生活美好】youya-vue
    【美好生活】 haha-edu
    【生活美好】Mobile-H5-web-for-vue
    vue模块引用错误【CaseSensitivePathsPlugin】
    v-auth
    npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained
    【每日一练】两个数字长度一致,不一致的前面加0补齐
    ERROR: CAN'T FIND PYTHON EXECUTABLE "PYTHON", YOU CAN SET THE PYTHON ENV VARIABLE.解决办法
    [ERROR] ionic-app-scripts has unexpectedly closed (exit code 1).
  • 原文地址:https://www.cnblogs.com/pypua/p/10075114.html
Copyright © 2011-2022 走看看