(1)使用set方法:

public class Book {
  private String bookname;
public void setBookname(String bookname) {
    this.bookname = bookname;
}

xml配置:

<bean ></property>
</bean>

(2)有参数的构造

public class PropertDemo1 {
    private String username;
    public PropertDemo1(String username) {
        this.username = username;
    }

xml配置:

<bean ></constructor-arg>
 </bean>

(3)使用接口注入

public Interface Dao{

  public void delete(String name);

}

public class DaoImpl implements Dao{

   private String name;

   public void delete(String name){

       this.name=name;

      }

}

在spring框架里,只允许前两种方式。

相关文章:

  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-06-07
  • 2021-06-30
  • 2021-05-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-12-06
  • 2022-12-23
  • 2021-08-04
  • 2022-01-01
  • 2022-02-06
相关资源
相似解决方案