zoukankan      html  css  js  c++  java
  • spring_150802_resource

    接口Service:

    package com.spring.service;
    
    public interface DogPetService {
        public void queryAllDogPets();
    }

    实现类ServiceImpl:

    package com.spring.service.impl;
    
    import java.util.List;
    
    import javax.annotation.Resource;
    
    import com.spring.service.DogPetService;
    import com.spring.dao.DogPetDAO;
    import com.spring.model.DogPet;
    
    public class DogPetServiceImpl implements DogPetService{
        
        private DogPetDAO dogPetDAO;
    
        public DogPetDAO getDogPetDAO() {
            return dogPetDAO;
        }
        
        @Resource(name="dogPetDAO1")
        public void setDogPetDAO(DogPetDAO dogPetDAO) {
            this.dogPetDAO = dogPetDAO;
        }
    
        @Override
        public void queryAllDogPets() {
            List<DogPet> list = dogPetDAO.queryAllDogPets();
            if(list != null)
            {
                for(DogPet d:list)
                {
                    System.out.println(d.toString());
                }
            }
        }
        
        
    }

    Service的调用DAO类:

    package com.spring.dao;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.spring.model.DogPet;
    
    public class DogPetDAO {
        
        public List<DogPet> queryAllDogPets()
        {
            List<DogPet> list = new ArrayList<DogPet>();
            
            DogPet d1 = new DogPet();
            d1.setId(1111);
            d1.setName("dog1");
            d1.setAge(4);
            d1.setKind("buladuo");
            d1.setSex("B");
            d1.setHealth("good");
            DogPet d2 = new DogPet();
            d2.setId(2222);
            d2.setName("dog2");
            d2.setAge(3);
            d2.setKind("buladuo");
            d2.setSex("G");
            d2.setHealth("good");
            
            list.add(d1);
            list.add(d2);
            
            return list;
        }
    }

    配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
            xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
            xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
        <context:annotation-config/>
        
        <bean id="dogPetService" class="com.spring.service.impl.DogPetServiceImpl">
        
        </bean>
        
        <bean id="dogPetDAO1" class="com.spring.dao.DogPetDAO">
        
        </bean>
    </beans>            

    test类:

    package com.spring.test;
    
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import com.spring.service.DogPetService;
    
    public class ResourceTest {
        
        @Test
        public  void queryAllDogPets()
        {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
            DogPetService dogPetService = (DogPetService)ctx.getBean("dogPetService");
            dogPetService.queryAllDogPets();
        }
    
    }
  • 相关阅读:
    python面试题解析(python基础篇80题)
    python面试题
    网络IO模型 主要 IO多路复用
    线程队列 线程池 协程
    线程的Thread模块 同步控制:锁,事件,信号量,条件,定时器
    进程池,线程的理论,Threading.Thread来创建线程
    进程之间的通信(IPC),对列,管道,数据共享.进程池初识
    Process 进程之间的数据隔离问题,守护进程,锁,信号量,事件
    js get the local domain and path fast
    github jekyll blog
  • 原文地址:https://www.cnblogs.com/yanff/p/4791522.html
Copyright © 2011-2022 走看看