08_Spring实现action调用service,service调用dao的过程
【工程截图】

【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的过程的更多相关文章
- 12_注解04_注解实现Action调用Service,Service调用Dao的过程
[工程截图] [PersonDao.java] package com.HigginCui.annotation; public interface PersonDao { public void s ...
- java中Action层、Service层和Dao层的功能区分
Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO只 ...
- Java中Action层、Service层、Modle层和Dao层的功能区分
一.Java中Action层.Service层.Modle层和Dao层的功能区分: 首先,这是现在最基本的分层方式,结合了SSH架构. modle层就是对应的数据库表的实体类.(即domain) Da ...
- Action层, Service层 和 Dao层的功能区分
Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO ...
- android 中activity调用远程service中的方法之 aidl的使用
服务端:只有服务,没有界面 1.编写interface文件,复制到 .aidl 文件中,并去掉其中的public 等修饰符.系统会自动在gen目录下生成对应的java文件 (对应本地调用中的接口文件 ...
- 使用wsimport和JAX-WS调用Web Service接口
本文简单举例说明如何使用wsimport工具和JAX-WS API调用Web Service接口.此方法的优点:使用JDK自带的工具和API接口,无需依赖第三方库. JDK版本:1.8.0_141开发 ...
- Java 调用Web service 加入认证头(soapenv:Header)
前言 有时候调用web service 会出现 Message does not conform to configured policy [ AuthenticationTokenPolicy(S) ...
- 用JavaScript调用WCF Service
原创地址:http://www.cnblogs.com/jfzhu/p/4039604.html 转载请注明出处 前面介绍过<Step by Step 创建一个WCF Service>和& ...
- ORACLE存储过程调用Web Service
1. 概述 最近在ESB项目中,客户在各个系统之间的服务调用大多都是在oracle存储过程中进行的,本文就oracle存储过程调用web service来进行说明.其他主流数据库,比如mysql和sq ...
- 在Salesforce中向外公布Service去创建Lead,并且用Asp.Net去调用此Service
1):在Salesforce中如何配置,向外公布此Service,请看如下链接: http://www.shellblack.com/marketing/web-to-lead/ 2):如何在Asp. ...
随机推荐
- 【Stage3D学习笔记续】真正的3D世界(六):空间大战
这就是书上的最终效果了,一个完整的空间大战游戏: 点击查看源码 这里并没有太多的新知识,所涉及的东西更多的是游戏开发方面的优化和技巧,下面我们大家一起来看看: 飞船: 类似粒子效果中的粒子创建方法,我 ...
- ThindPad x230 无法U盘启动
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- ASP.net中的Cache使用介绍
1.1.1 摘要(http://www.cnblogs.com/rush/archive/2012/06/30/2571438.html) 最近我们的系统面临着严峻性能瓶颈问题,这是由于访问量增加,客 ...
- Android设备上i-jetty环境的搭建-手机上的web服务器
本文主要跟大家分享如何将一台Android设备打造成一个web服务器使用. 编译i-jetty 1.将源码download下来,http://code.google.com/p/i-jetty/dow ...
- android学习日记06--View视图
一.android 界面开发 1.三个重要的类:View视图.Canvas画布.Paint画笔2.android 界面开发常用三种视图 View --只能在主线程中更新,没有缓存 ...
- Linux HugePages及MySQL 大页配置
http://blog.csdn.net/dba_waterbin/article/details/9669929 ㈠ HugePages简介 HugePages是 ...
- LayoutInflater
Android中LayoutInflater的使用 博客分类: Android Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater的作用类似于 f ...
- win10.10 激活
最近几天一直有同学来找我说,为什么用密钥或kms神龙版都无法激活win8/8.1.win10,于是我就让这些同学给我截图,结果他们激活出错的信息基本都一样,都是错误:“0XC004F074 软件授权服 ...
- Mechanism of Loading Resources
Mechanism of Loading Resources 1. Distributed strategy 1.1. Developer guilde 1.2. Notes 2. Centraliz ...
- MySQL(16):Select-union(联合查询)
1. Select-union(联合查询) union用于把来自许多SELECT语句的结果组合到一个结果集合中. 用法: SELECT ...UNION [ALL | DISTINCT]SELECT ...