• Spring常用注解


    一、使用注解之前首先要在applicationContext.xml中开启自动扫描功能,其中base-package为需要扫描的包

    <context:annotation-config/>
    <context:component-scan base-package="com.dongtian.MyBatis_Spring.*"/>

    二、常用注解

    1、@Configuration把一个类作为一个IoC容器,它的某个方法头上如果注册了@Bean,就会作为这个Spring容器中的Bean。

    2、@Service("courseDAO")

      @Scope("prototype")

    相当于:

    <bean id="courseDAO" class="xxx" scope="prototype">   
    </bean>

     举例:

    @Service
    public class UserServiceImp implements UserService{
        @Autowired //把UserMappper作为属性注入
        private UserMapper userMapper = null;
        //设置隔离级别,传播行为
        @Transactional(propagation = Propagation.REQUIRES_NEW,
                isolation=Isolation.READ_COMMITTED)
        public void insertUser(User user) {
            userMapper.insertUser(user);
        }
    
    }

    3、@Repository用于标注数据访问组件,即DAO组件。

    @Repository
    public interface UserMapper {
        public void insertUser(User user);
        public User findUsers(String username);
    }

    4、@Service用于标注业务层组件、 
    5、@Controller用于标注控制层组件(如struts中的action)

    原文:https://www.cnblogs.com/xingzc/p/5777814.html

  • 相关阅读:
    线上项目部署
    day26 面向对象 单例模式总结
    阿里云服务器,更换操作系统步骤总结
    后端for循环补充
    前端,css
    django-admin 仿写stark组件action,filter筛选过滤,search查询
    7.20晚作业
    用户和群组管理
    7.19 晚作业
    目录和文件管理
  • 原文地址:https://www.cnblogs.com/dongtian-blogs/p/10821519.html
Copyright © 2020-2023  润新知