Spring IoC容器与Bean管理 作业3-7

来源:3-7 自由编程

rudtjd

2023-03-02 19:55:50

package com.imooc.spring.ioc.entity;

public class Book {
    private Integer id;
    private String name;
    private Float price;

    public Book() {
        System.out.println("book对象通过默认构造方法创建"+this);
    }

    public Book(Integer id, String name, Float price) {
        this.id = id;
        this.name = name;
        this.price = price;
        System.out.println("book对象通过带参构造方法创建"+this);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd">

     <bean id="book1" class="com.imooc.spring.ioc.entity.Book">
    </bean>
    <bean id="book2" class="com.imooc.spring.ioc.entity.Book">
        <constructor-arg name="id" value="01"></constructor-arg>
        <constructor-arg name="price" value="10"></constructor-arg>
        <constructor-arg name="name" value="00"></constructor-arg>
    </bean>
</beans>


写回答

1回答

好帮手慕小蓝

2023-03-03

同学你好,同学的代码符合题目要求,逻辑清晰,书写规范,做的很棒。

祝学习愉快~

0

0 学习 · 9886 问题

查看课程