List集合的引入

14.1新建一个User1实体类;

package com.eduask.entity3;

import java.util.List;

import java.util.Map;

public class User1 {

private int id;

private String name;

private String pwd;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getPwd() {

return pwd;

}

public void setPwd(String pwd) {

this.pwd = pwd;

}

@Override

public String toString() {

return "User1 [id=" + id + ", name=" + name + ", pwd=" + pwd + "]";

}

public User1(int id, String name, String pwd) {

super();

this.id = id;

this.name = name;

this.pwd = pwd;

}

public User1() {

super();

// TODO Auto-generated constructor stub

}

}

14.2新建一个Demo1的实体类,引入List集合中的User1类;

package com.eduask.entity3;

import java.util.List;

//新建一个Demo1的实体类;

public class Demo1 {

private int id;

private String name;

private String  pwd;

private List users1;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getPwd() {

return pwd;

}

public void setPwd(String pwd) {

this.pwd = pwd;

}

public List getUsers1() {

return users1;

}

public void setUsers1(List users1) {

this.users1 = users1;

}

@Override

public String toString() {

return "Demo1 [id=" + id + ", name=" + name + ", pwd=" + pwd + "]\nusers1="

+ users1 + "]";

}

public Demo1(int id, String name, String pwd, List users1) {

super();

this.id = id;

this.name = name;

this.pwd = pwd;

this.users1 = users1;

}

public Demo1() {

super();

// TODO Auto-generated constructor stub

}

}

14.3 新建一个TestDemo1的实体类;

package com.eduask.entity3;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDemo1 {

public static void main(String[] args) {

ClassPathXmlApplicationContext cx=new ClassPathXmlApplicationContext("entity3Xml/demo1.xml");

Demo1 demo1=(Demo1) cx.getBean("demo1");

System.out.println(demo1);

}

}

14.4 新建一个demo1.xml的配置文件;






























14.5程序运行如下:

Demo1 [id=1, name=tom, pwd=123456]
users1=[User1 [id=1, name=name1, pwd=pwd1], User1 [id=2, name=name2, pwd=pwd2], User1 [id=2, name=name3, pwd=pwd3]]]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值