【工程截图】

【PersonDao.java】

package com.HigginCui.dao;

public interface PersonDao {
public void savePerson();
}

【PersonDaoImpl.java】

package com.HigginCui.dao;

public class PersonDaoImpl implements PersonDao{
@Override
public void savePerson() {
System.out.println("save Person...");
}
}

【PersonService.java】

package com.HigginCui.Service;

public interface PersonService {
public void savePerson();
}

【PersonServiceImpl.java】

package com.HigginCui.Service;

import com.HigginCui.dao.PersonDao;

public class PersonServiceImpl implements PersonService{
private PersonDao personDao;
//personDao的set方法
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
@Override
public void savePerson() {
this.personDao.savePerson();
}
}

【PersonAction.java】

package com.HigginCui.action;

import com.HigginCui.Service.PersonService;

public class PersonAction {
private PersonService personService;
//personService的set方法
public void setPersonService(PersonService personService) {
this.personService = personService;
}
public String savePerson(){
this.personService.savePerson();
return "saveOK...";
}
}

【applicationContext.xml】

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="personDao" class="com.HigginCui.dao.PersonDaoImpl"></bean> <bean id="personService" class="com.HigginCui.Service.PersonServiceImpl">
<property name="personDao">
<ref bean="personDao"/>
</property>
</bean> <bean id="personAction" class="com.HigginCui.action.PersonAction">
<property name="personService">
<ref bean="personService"/>
</property>
</bean>
</beans>

【testPerson.java】

package com.HigginCui.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.HigginCui.action.PersonAction; public class testPerson {
@Test
public void test(){
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
PersonAction personAction=(PersonAction) context.getBean("personAction");
String str=personAction.savePerson();
System.out.println(str);
}
}

【运行结果】

save Person...
saveOK...

【小结】

实现了完全的面向接口编程,在代码端没有必要关心一个接口的实现类是什么。

08_Spring实现action调用service,service调用dao的过程的更多相关文章

  1. 12_注解04_注解实现Action调用Service,Service调用Dao的过程

    [工程截图] [PersonDao.java] package com.HigginCui.annotation; public interface PersonDao { public void s ...

  2. java中Action层、Service层和Dao层的功能区分

    Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO只 ...

  3. Java中Action层、Service层、Modle层和Dao层的功能区分

    一.Java中Action层.Service层.Modle层和Dao层的功能区分: 首先,这是现在最基本的分层方式,结合了SSH架构. modle层就是对应的数据库表的实体类.(即domain) Da ...

  4. Action层, Service层 和 Dao层的功能区分

    Action/Service/DAO简介:  Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO ...

  5. android 中activity调用远程service中的方法之 aidl的使用

    服务端:只有服务,没有界面 1.编写interface文件,复制到 .aidl 文件中,并去掉其中的public 等修饰符.系统会自动在gen目录下生成对应的java文件  (对应本地调用中的接口文件 ...

  6. 使用wsimport和JAX-WS调用Web Service接口

    本文简单举例说明如何使用wsimport工具和JAX-WS API调用Web Service接口.此方法的优点:使用JDK自带的工具和API接口,无需依赖第三方库. JDK版本:1.8.0_141开发 ...

  7. Java 调用Web service 加入认证头(soapenv:Header)

    前言 有时候调用web service 会出现 Message does not conform to configured policy [ AuthenticationTokenPolicy(S) ...

  8. 用JavaScript调用WCF Service

    原创地址:http://www.cnblogs.com/jfzhu/p/4039604.html 转载请注明出处 前面介绍过<Step by Step 创建一个WCF Service>和& ...

  9. ORACLE存储过程调用Web Service

    1. 概述 最近在ESB项目中,客户在各个系统之间的服务调用大多都是在oracle存储过程中进行的,本文就oracle存储过程调用web service来进行说明.其他主流数据库,比如mysql和sq ...

  10. 在Salesforce中向外公布Service去创建Lead,并且用Asp.Net去调用此Service

    1):在Salesforce中如何配置,向外公布此Service,请看如下链接: http://www.shellblack.com/marketing/web-to-lead/ 2):如何在Asp. ...

随机推荐

  1. Oracle- 正则表达式查询

    发现Oracle支持正则表达式.先收藏. ORACLE中的支持正则表达式的函数主要有下面四个:1,REGEXP_LIKE :与LIKE的功能相似2,REGEXP_INSTR :与INSTR的功能相似3 ...

  2. 关于 javascript:void(0) 的使用

    在 Wep App 中,我们经常需要在 JavaScript 中处理链接的点击.因此,我们希望用户点击 <a> 元素时阻止它的默认行为.此时我们可以用很多不同的方法来处理.例如: < ...

  3. 从Web借鉴UI设计

    从Web借鉴UI设计 用户体验已经成为衡量应用软件质量的重要标准.在过去我们可能会惊叹于某个Web应用的华丽界面,现在,随着HTML5的强势登场,各类表现层技术及开发框架的发布,Web与窗体应用的界限 ...

  4. MVC返回http状态码

    //controller ); //asp.net return HttpStatusCode.OK

  5. SAP增强总结-第二代增强(SMOD、CMOD)【转载】

    第二代增强比第二代增强安全性提高了很多,第一代增强毕竟是在原标准程序中修改,大部分传递参数都可以直接使用,第二代增强做了一些封装,对用户可以修改的参数做了限制. 1.增强点查找方法 首先根据事物码找到 ...

  6. android学习日记22--Animation动画简介

    Animation动画主要有两种:帧动画(Frame Animation)和补间动画(Tween Animation).补间动画主要包括对位置.角度.尺寸等属性的变化,而帧动画则是通过若干帧图片轮流切 ...

  7. 认识CoreData-多线程

    CoreData使用相关的技术点已经讲差不多了,我所掌握的也就这么多了.... 在本篇文章中主要讲CoreData的多线程,其中会包括并发队列类型.线程安全等技术点.我对多线程的理解可能不是太透彻,文 ...

  8. PHP算法--将数字金额转换成大写金额

    最近在看一些PHP算法题,遇到一个将数字金额转换成大写金额的小算法题,这里贴出自己的一个例子. 注:这个小算法适用于10万以内的金额. <?php //$num = 12345.67; func ...

  9. nodejs 微信中使用file组件上传图片在某些机型上点击无反应

    看下下面的代码: <form action="/" class="file_upload" method="post" enctype ...

  10. java集合总结

    java中集合是很重要的一点,巩固这边学习的知识,把知识理一下 按马士兵的视频,总结的也很好,集合就是一个“1136” 1个图,1个类Collections,3个知识点:增强for循环,泛型,打包和解 ...