标签:pojo center tor rgs odi getch imp dom VID
Video.java
package net.cybclass.sp.domain; public class Video { private int id; private String title; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { System.out.println("Video setTitle被调用"); this.title = title; } }
applicationContext.xml
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="video" class="net.cybclass.sp.domain.Video"> <property name="id" value="9"></property> <property name="title" value="Spring5.X课程"></property> </bean> </beans>
app.java
package net.cybclass.sp; import net.cybclass.sp.domain.Video; import net.cybclass.sp.domain.VideoOrder; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class app { public static void main(String[] args) { ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml"); Video video=(Video) applicationContext.getBean("video"); System.out.println(video); } }
验证
Video.java
package net.cybclass.sp.domain; public class Video { public Video(int id, String title) { System.out.println("Video 构造函数被调用"); this.id = id; this.title = title; } private int id; private String title; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
applicationContext.xml
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="video" class="net.cybclass.sp.domain.Video"> <constructor-arg name="id" value="8"></constructor-arg> <constructor-arg name="title" value="Spring5.X课程"></constructor-arg> </bean> </beans>
app.java
package net.cybclass.sp; import net.cybclass.sp.domain.Video; import net.cybclass.sp.domain.VideoOrder; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class app { public static void main(String[] args) { ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml"); Video video=(Video) applicationContext.getBean("video"); System.out.println(video); } }
验证
<bean id="video" class="net.cybclass.sp.domain.Video"> <!--list 类型注入--> <property name="chapterList"> <list> <value>第一章SpringBoot</value> <value>第二章Mybatis</value> <value>第三章Spring</value> </list> </property> <!--注入map--> <property name="videoMap"> <map> <entry key="1" value="SpringCloud课程层"></entry> <entry key="2" value="面试宝典"></entry> <entry key="3" value="JavaWeb课程"></entry> </map> </property> </bean> <bean id="videoOrder" class="net.cybclass.sp.domain.VideoOrder"> <property name="id" value="8"></property> <property name="outTradeNo" value="12312"></property> <property name="video" ref="video"></property> </bean>
Video.java
package net.cybclass.sp.domain; import java.util.List; import java.util.Map; public class Video { private int id; private String title; private List<String> chapterList; private Map<Integer, String> videoMap; public List<String> getChapterList() { return chapterList; } public void setChapterList(List<String> chapterList) { this.chapterList = chapterList; } public Map<Integer, String> getVideoMap() { return videoMap; } public void setVideoMap(Map<Integer, String> videoMap) { this.videoMap = videoMap; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
applicationContext.xml
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="video" class="net.cybclass.sp.domain.Video"> <!--list 类型注入--> <property name="chapterList"> <list> <value>第一章SpringBoot</value> <value>第二章Mybatis</value> <value>第三章Spring</value> </list> </property> <!--注入map--> <property name="videoMap"> <map> <entry key="1" value="SpringCloud课程层"></entry> <entry key="2" value="面试宝典"></entry> <entry key="3" value="JavaWeb课程"></entry> </map> </property> </bean> </beans>
app.java
package net.cybclass.sp; import net.cybclass.sp.domain.Video; import net.cybclass.sp.domain.VideoOrder; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class app { public static void main(String[] args) { ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml"); Video video=(Video) applicationContext.getBean("video"); System.out.println(video.getChapterList()); System.out.println(video.getVideoMap()); } }
验证
标签:pojo center tor rgs odi getch imp dom VID
原文地址:https://www.cnblogs.com/chenyanbin/p/13303091.html