一、构造方法方式注入

1、项目结构如下:

 spring属性依赖注入

2、新建Customer类

package hjp.spring.attributeinject;

public class Customer {
    private String name;
    private Integer age;
    private String city;

    public Customer() {

    }

    public Customer(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Customer(Integer age, String city) {
        this.age = age;
        this.city = city;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String toString() {
        return "Customer [name=" + name + ", age=" + age + ", city=" + city + "]";
    }
}
Cusomer

相关文章:

  • 2021-06-29
  • 2019-09-24
  • 2022-01-01
  • 2018-07-27
  • 2020-05-04
  • 2021-07-15
  • 2020-06-11
  • 2017-12-08
猜你喜欢
  • 2018-02-03
  • 2020-04-15
  • 2021-08-20
  • 2020-05-27
  • 2021-01-27
  • 2021-02-25
  • 2021-02-28
  • 2021-11-19
相关资源
相似解决方案