Spring 基础实例1
2016-01-05 11:07
696 查看
applicationContext.xml
Action:
BEAN:
Service:
DAO:
<bean id="bookAction" class="com.xml.spring.action.BookAction"> <property name="bookService" ref="bookService"></property> </bean> <bean id="bookService" class="com.xml.spring.service.BookService"> <property name="bookDao" ref="bookDao"></property> </bean> <bean id="bookDao" class="com.xml.spring.dao.BookDao"></bean> <bean id="parentAction" class="com.xml.spring.action.ParentAction"> <property name="stu" ref="student" /> <property name="teh" ref="teacher" /> </bean> <bean id="student" class="com.xml.spring.comom.Student"> <property name="name" value="tom" /> <property name="sex" value="men" /> <property name="age" value="10" /> </bean> <bean id="teacher" class="com.xml.spring.comom.Teacher" parent="student"> <property name="name" value="jim" /> <property name="age" value="25" /> <property name="course" value="computer" /> </bean>
Action:
@Controller public class BookAction { private BookService bookService; public BookService getBookService() { return bookService; } public void setBookService(BookService bookService) { this.bookService = bookService; } @RequestMapping(value = ("/xml/book")) public void test() { System.out.println("-----BookAction.test function-------------"); bookService.test(); } }
@Controller public class ParentAction { private Student stu; private Teacher teh; @RequestMapping(value = "/parent") public void parent1() { System.out.println("---s:" + stu.getAge() + "----" + stu.getName() + "---" + stu.getSex()); System.out.println(teh.getAge() + "--" + teh.getCourse() + "--" + teh.getName() + "------" + teh.getSex()); } public Student getStu() { return stu; } public void setStu(Student stu) { this.stu = stu; } public Teacher getTeh() { return teh; } public void setTeh(Teacher teh) { this.teh = teh; } }
BEAN:
/* * Creation : 26 Nov 2015 */ package com.xml.spring.comom; /** * The Class Student. */ public class Student { /** The name. */ private String name; /** The sex. */ private String sex; /** The age. */ private int age; /** * Gets the name. * * @return the name */ public String getName() { return name; } /** * Sets the name. * * @param name the new name */ public void setName(String name) { this.name = name; } /** * Gets the sex. * * @return the sex */ public String getSex() { return sex; } /** * Sets the sex. * * @param sex the new sex */ public void setSex(String sex) { this.sex = sex; } /** * Gets the age. * * @return the age */ public int getAge() { return age; } /** * Sets the age. * * @param age the new age */ public void setAge(int age) { this.age = age; } }
/* * Creation : 26 Nov 2015 */ package com.xml.spring.comom; public class Teacher { private String name; private String sex; private int age; private String course; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } }
Service:
/* * Creation : 24 Nov 2015 */ package com.xml.spring.service; import com.xml.spring.dao.BookDao; public class BookService { private BookDao bookDao; public BookDao getBookDao() { return bookDao; } public void setBookDao(BookDao bookDao) { this.bookDao = bookDao; } public void test() { // TODO Auto-generated method stub System.out.println("---------BookService .test function -------"); bookDao.test(); } }
DAO:
/* * Creation : 24 Nov 2015 */ package com.xml.spring.dao; public class BookDao { public void test() { // TODO Auto-generated method stub System.out.println("--------------Book Dao .test----------"); } }
相关文章推荐
- Spring+Quartz实现定时任务的配置方法
- java web springMVC response wirte image demo
- JAVA 的 mysql blob操作 -1 比较全面,但是格式乱
- 简单说说Spring Security 使用(附加验证码登录,自定义认证)
- 添加Java文档注释
- Java内存模型:线程并发下的对象逸出
- Myeclipse10破解 注册之前找不到common文件夹的问题
- 【Java并发编程实战】- Lock
- 为什么写Java程序需要接口
- 【Java并发编程实战】- Synchronized
- Java 多线程 并发编程
- Java中反射的用法
- Spring 基础 实例
- eclipse快捷键总结
- JAVA Map集合类简介
- Posting JSON to Spring MVC Controller
- Spring中bean的生命周期
- Spring + iBATIS完整示例
- Java 单例模式详解
- java synchronized详解