提交 fc4818ba 编写于 作者: Q qinyingjie

fix:测试添加编号

上级 5bfa133e
package com.kwan.spring5;
import java.util.List;
/**
* 书籍 set方法注入属性
*
......@@ -9,13 +11,17 @@ package com.kwan.spring5;
*/
public class Book {
/**
* 姓名
* 名称
*/
private String bname;
/**
* 作者
*/
private String bauthor;
/**
* 书名
*/
private List<String> list;
/**
* 创建属性对应的set方法
......@@ -28,11 +34,16 @@ public class Book {
this.bauthor = bauthor;
}
public void setList(List<String> list) {
this.list = list;
}
@Override
public String toString() {
return "Book{" +
"bname='" + bname + '\'' +
", bauthor='" + bauthor + '\'' +
", list=" + list +
'}';
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
https://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<!--第二步:使用 util 标签完成 list 集合注入提取-->
<!--把集合注入部分提取出来-->
<!--1 提取list集合类型属性注入-->
<util:list id="bookList">
<value>易筋经</value>
<value>九阴真经</value>
<value>九阳神功</value>
</util:list>
<!--2 提取list集合类型属性注入使用-->
<bean id="book" class="com.kwan.spring5.Book" scope="prototype">
<property name="list" ref="bookList"></property>
</bean>
</beans>
\ No newline at end of file
import com.kwan.spring5.Book;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* 测试ioc注入
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/11/12 18:43
*/
public class Spring_08_BookTest {
@Test
public void test1() {
ApplicationContext ctx =
new ClassPathXmlApplicationContext("spring10.xml");
Book book = (Book) ctx.getBean("book");
System.out.println(book);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册