zoukankan      html  css  js  c++  java
  • Spring 一二事(6)

    1     <bean id="personAction" class="com.lee.spring008.IOC.DI.MVC.PersonAction">
    2         <property name="stuService" ref="stuService"></property>
    3     </bean>
    4     <bean id="stuService" class="com.lee.spring008.IOC.DI.MVC.StuServiceImpl">
    5         <property name="stuDAO" ref="stuDAO"></property>
    6     </bean>
    7     <bean id="stuDAO" class="com.lee.spring008.IOC.DI.MVC.StuDAOImpl"></bean>

    IStuDAO.java

    1 package com.lee.spring008.IOC.DI.MVC;
    2 
    3 public interface IStuDAO {
    4     public void saveStu();
    5 }

    IStuService.java

    1 package com.lee.spring008.IOC.DI.MVC;
    2 
    3 public interface IStuService {
    4     public void saveStu();
    5 }

    PersonAction.java

     1 package com.lee.spring008.IOC.DI.MVC;
     2 
     3 public class PersonAction {
     4 
     5     public IStuService stuService;
     6 
     7     public void displaySave() {
     8         stuService.saveStu();
     9     }
    10 
    11     public IStuService getStuService() {
    12         return stuService;
    13     }
    14 
    15     public void setStuService(IStuService stuService) {
    16         this.stuService = stuService;
    17     }
    18 
    19 }

    StuDAOImpl.java

     1 package com.lee.spring008.IOC.DI.MVC;
     2 
     3 public class StuDAOImpl implements IStuDAO {
     4 
     5     @Override
     6     public void saveStu() {
     7         System.out.println("dao: saving stu...");
     8     }
     9 
    10 }

    StuServiceImpl.java

     1 package com.lee.spring008.IOC.DI.MVC;
     2 
     3 public class StuServiceImpl implements IStuService {
     4 
     5     public IStuDAO stuDAO;
     6     
     7     @Override
     8     public void saveStu() {
     9         System.out.println("service: saving stu...");
    10         stuDAO.saveStu();
    11     }
    12 
    13     public IStuDAO getStuDAO() {
    14         return stuDAO;
    15     }
    16 
    17     public void setStuDAO(IStuDAO stuDAO) {
    18         this.stuDAO = stuDAO;
    19     }
    20 
    21 }

    测试:

    1 @Test
    2     public void testPersonAction() {
    3         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    4         PersonAction person = (PersonAction)context.getBean("personAction");
    5         person.displaySave();
    6     }

    github地址:https://github.com/leechenxiang/maven-spring001-helloworld

  • 相关阅读:
    xprintf
    Socket调试助手
    ESP8266开发
    WPS for Linux 界面改为中文
    uBlock Origin 广告屏蔽
    Ubuntu删除多余旧内核
    FFmpeg命令
    Mysql-connector-java驱动版本问题
    crontab任务重复执行?不执行?不按照配置执行?大概率是配置出错了!!!
    Binding(四):数据校验
  • 原文地址:https://www.cnblogs.com/leechenxiang/p/5305518.html
Copyright © 2011-2022 走看看