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

spring_150802_resource的更多相关文章

随机推荐

  1. js 获取字符串中最后一个斜杠后面的内容

    var str = "/asdasf/asfaewf/agaegr/trer/rhh"; var index = str .lastIndexOf("\/"); ...

  2. Labview实现单边带信号调制(SSB)[滤波法]

    Labview实现单边带信号调制(SSB)[滤波法] 首先用信号仿真器得到一个被调制信号m(t),以及载波信号,该实验选择正弦信号作为载波信号. 根据调制器模型 得到一个结果信号. 其中,H(w)的选 ...

  3. sql优化点整理

    此文是我最早开始sql优化至今整理的小知识点和经常遇到的问题,弄懂这些对优化大型的sql会有不少帮助 ---------------------------------使用了多余的外连接------- ...

  4. “我爱淘”冲刺阶段Scrum站立会议6

    完成任务: 对大部分的布局已经做好了布置. 计划任务: 实现数据库的链接,将页面功能完善. 遇到问题: 使用webservice对数据的提取,用数据库将书的信息展示软件中.

  5. ASP.Net MVC中数据库数据导出Excel,供HTTP下载(转)

    转自http://www.cnblogs.com/hipo/archive/2012/03/13/2394019.html 一.关于下载 一般对下载权限有没有限制,或安全性要求不高的情况下,基于web ...

  6. MyEclipse构建WebService案例

    Hi,大家好! 今天主要和大家分享,如何搭建一个Web服务,做Android开发,不可避免会涉及到客户端开发,我们怎么样来实现一个服务端,怎么样来实现一个客户端,并相互传递数据.就算调用别人的服务时, ...

  7. GitHub教程--上传项目四步法 GitBash命令行下使用方法

    之前就用过GitHub,感觉用GitHub托管自己的代码非常不错.可是之前用的都是窗口化的TortoiseGit,省了很多命令行的操作,但是个人非常喜欢使用命令行,于是,今天就试着用了用GitBash ...

  8. 重读《Struts In Action》

    Figure   1.1. The Java Servlet API exposes the HTTP client/server protocol to the Java   platform. S ...

  9. 看我是一只IT小小鸟有感

    当我看了<我是一只IT小小鸟>后,有许多的感想.就像许多作者一样,在接触计算机这个专业时都有许多的抱怨,对这个专业的不了解,对这个专业不知道从何学起有深深的无助感,对这个专业在未来的发展有 ...

  10. 待验证的一些IOS问题

    1.images.assert中的图片格式必须是png.(jpg格式的图片不行)