spring学习笔记五

一、Bean设置基础类型

1.1、BookDao接口和实现类

public interface BookDao {
    void save();
}

public class BookDaoImpl implements BookDao {

    private int connectionNum;
    private String databaseName;

    public void setConnectionNum(int connectionNum) {
        this.connectionNum = connectionNum;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }



    public void save(){
        System.out.println("book dao save......" + databaseName+","+ connectionNum);
    }
}

1.2、配置文件



    

        
        
    

1.3、总结

  • bean中基本数据类型是设置property中value属性

二、 Bean设置引用类型

2.1、BookService接口和实现类

public interface BookService {
    void save();
}
public class BookServiceImpl implements BookService, InitializingBean, DisposableBean {
    private BookDao bookDao;
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }



    public void save(){
//        System.out.println("book service save..");
        bookDao.save();
        userDao.save();
    }

    // 提供对应的set方法
    public void setBookDao(BookDao bookDao) {
        this.bookDao = bookDao;
    }

    public void destroy() throws Exception {
        System.out.println("service destroy");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("service init");
    }
}

2.2、配置文件




    
        
        
        
    
    
    
        
        
        
    

2.3、总结

  • 基本数据类型使用的是value 
  • 引用类型使用的是ref

你可能感兴趣的:(java,spring,学习,笔记)