【工程截图】

【PersonDao.java】

  1. package com.HigginCui.dao;
  2.  
  3. public interface PersonDao {
  4. public void savePerson();
  5. }

【PersonDaoImpl.java】

  1. package com.HigginCui.dao;
  2.  
  3. public class PersonDaoImpl implements PersonDao{
  4. @Override
  5. public void savePerson() {
  6. System.out.println("save Person...");
  7. }
  8. }

【PersonService.java】

  1. package com.HigginCui.Service;
  2.  
  3. public interface PersonService {
  4. public void savePerson();
  5. }

【PersonServiceImpl.java】

  1. package com.HigginCui.Service;
  2.  
  3. import com.HigginCui.dao.PersonDao;
  4.  
  5. public class PersonServiceImpl implements PersonService{
  6. private PersonDao personDao;
  7. //personDao的set方法
  8. public void setPersonDao(PersonDao personDao) {
  9. this.personDao = personDao;
  10. }
  11. @Override
  12. public void savePerson() {
  13. this.personDao.savePerson();
  14. }
  15. }

【PersonAction.java】

  1. package com.HigginCui.action;
  2.  
  3. import com.HigginCui.Service.PersonService;
  4.  
  5. public class PersonAction {
  6. private PersonService personService;
  7. //personService的set方法
  8. public void setPersonService(PersonService personService) {
  9. this.personService = personService;
  10. }
  11. public String savePerson(){
  12. this.personService.savePerson();
  13. return "saveOK...";
  14. }
  15. }

【applicationContext.xml】

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:aop="http://www.springframework.org/schema/aop"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  7. http://www.springframework.org/schema/aop
  8. http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
  9.  
  10. <bean id="personDao" class="com.HigginCui.dao.PersonDaoImpl"></bean>
  11.  
  12. <bean id="personService" class="com.HigginCui.Service.PersonServiceImpl">
  13. <property name="personDao">
  14. <ref bean="personDao"/>
  15. </property>
  16. </bean>
  17.  
  18. <bean id="personAction" class="com.HigginCui.action.PersonAction">
  19. <property name="personService">
  20. <ref bean="personService"/>
  21. </property>
  22. </bean>
  23. </beans>

【testPerson.java】

  1. package com.HigginCui.test;
  2.  
  3. import org.junit.Test;
  4. import org.springframework.context.ApplicationContext;
  5. import org.springframework.context.support.ClassPathXmlApplicationContext;
  6. import com.HigginCui.action.PersonAction;
  7.  
  8. public class testPerson {
  9. @Test
  10. public void test(){
  11. ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
  12. PersonAction personAction=(PersonAction) context.getBean("personAction");
  13. String str=personAction.savePerson();
  14. System.out.println(str);
  15. }
  16. }

【运行结果】

  1. save Person...
  2. 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. 【转载】Android Studio 设置内存大小及原理

    http://www.cnblogs.com/justinzhang/p/4274985.html http://tsroad.lofter.com/post/376316_69363ae Andro ...

  2. .NET连接MySql数据库的方法及示例

    方法一: 使用MySQL推出的MySQL Connector/Net组件, 该组件是MySQL为ADO.NET访问MySQL数据库设计的.NET专用访问组件.完成该组件后,需要在项目中引用这个组件,也 ...

  3. ASC(1)G(上升时间最长的序列)

    G - Beautiful People Time Limit: 10000/5000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...

  4. Linux PAM&&PAM后门

    Linux PAM&&PAM后门 我是壮丁 · 2014/03/24 11:08 0x00 PAM简介 PAM (Pluggable Authentication Modules )是 ...

  5. Controllers

    Controllers Controllers are the bread and butter of the framework they control when a model is used ...

  6. 仿简书、淘宝等等App的View弹出效果

    昨天用简书App的时候觉得这个View的弹出效果特别好,而且非常平滑,所以我就尝试写了一个,和简书App上的效果基本一致了: 下面开始讲解: 1.首先我们要知道这个页面有几个View?这个页面其实有四 ...

  7. Asp.Net 之 未能加载文件或程序集 system.web.extensions 解决方法

    最近做项目发现未能加载文件或程序集的错误,这是由于我的机器上没有安装Ajax的原因.问题解决后,整理如下:表现:1."System.Web.Extensions, Version=1.0.61025. ...

  8. Google(谷歌)中国工程研究院 工程师 方坤 对学生朋友的一些建议

    对学生朋友的一点建议 发表者:Google(谷歌)中国工程研究院工程师 方坤 自去年春天加入谷歌,我曾多次随公司校园招聘团队一起走访各地院校,帮助公司发掘人才 .利用这样的出差机会到处走走看看,饱览祖 ...

  9. Guzzle Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON

    项目更新到正式平台时,出现Guzzle(5.3) client get请求出现:Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, ...

  10. SharePoint缓存导致访问慢解决

    产品发布到公网时,客户每次访问页面都很慢,经过查找原因,发现在服务器上的APPFabric缓存出错误了: APPFabric缓存服务作用:用作内存中缓存来存储应用程序访问的数据,从而提高应用程序性能. ...