接口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();
} }

最新文章

  1. 简单研究Android View绘制三 布局过程
  2. Word转图片(使用Spire.doc)
  3. G面经prepare: Data Stream Average
  4. android之location 根据接口获取经纬度信息
  5. CSS 列表 你知道吗
  6. web ajax跨域问题解决方案
  7. uva 10994 - Simple Addition
  8. 采用PopupWin控制消息推送功能
  9. JPA + SpringData 操作数据库 ---- 深入了解 SpringData
  10. Dynamics 365 Online 试用账号申请方式
  11. SuperMap iObject入门开发系列之二地下三维管线系统介绍
  12. C# 数据类型之 String(字符串)
  13. 使用log4net将C#日志发送到Elasticsearch
  14. 在同一台电脑上部署多个tomcat服务器
  15. 第十一章 非对称加密算法--DH
  16. 再学Java 之 形参个数可变函数
  17. centos 邮件服务 腾讯企业邮箱(免费) 使用iRedmail 需要有公网的centos主机 发邮件协议:smtp 端口25 收邮件协议:pop3 端口110 iredmail安装配置 使用邮箱系统 第三十一节课
  18. Classical Binary Search
  19. hdu 5833(欧拉路)
  20. Makefile的变量赋值和函数

热门文章

  1. linux调整分区大小
  2. iOS 各种系统文件目录 临时,缓存,document,lib,归档,序列化
  3. [转]webrtc学习: 部署stun和turn服务器
  4. 65.OV7725图像倒置180度
  5. 17.Quartus 怎么回读CPLD里面的东西
  6. [无人值守安装操作系统]_FTP+TFTP+DHCP+Kickstart+PXE_中遇到的错误
  7. 53张牌中找出缺少的牌的花色和点数--raid3,4,5,6的容错原理
  8. 【Merge K Sorted Lists】cpp
  9. 使用WatchService监控指定目录内的文件的改动
  10. 机器学习&amp;&amp;数据挖掘之一:决策树基础认识