本文共 3393 字,大约阅读时间需要 11 分钟。
本文转自 素颜猪 51CTO博客,原文链接:http://blog.51cto.com/suyanzhu/1910059
1.创建Maven项目,项目名称springdemo37,如图所示
1.0.0 shequ springdemo13 0.0.1-SNAPSHOT 1.7 UTF-8 UTF-8 codelds https://code.lds.org/nexus/content/groups/main-repo junit junit 4.10 org.springframework spring-core 4.1.4.RELEASE org.springframework spring-context 4.1.4.RELEASE org.springframework spring-jdbc 4.1.4.RELEASE mysql mysql-connector-java 5.1.34
package com.mycompany.shequ.bean;public class Forum { private int fid; private String name; private int displayOrder; public int getDisplayOrder() { return displayOrder; } public void setDisplayOrder(int displayOrder) { this.displayOrder = displayOrder; } public int getFid() { return fid; } public void setFid(int fid) { this.fid = fid; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "{fid=>"+this.fid+",name=>"+this.name+",displayOrder=>"+this.displayOrder+"}"; }}
package com.mycompany.shequ.bean;public class ForumPost { private int pid; private String name; private Forum forum; public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Forum getForum() { return forum; } public void setForum(Forum forum) { this.forum = forum; }}
package com.mycompany.shequ.test;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.mycompany.shequ.bean.ForumPost;public class AppTest { @Test public void beanTest(){ ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); ForumPost forumPost = (ForumPost)context.getBean("forumpostbean"); System.out.println(forumPost); }}
转载地址:http://qwtwa.baihongyu.com/