12_注解04_注解实现Action调用Service,Service调用Dao的过程
【工程截图】

【PersonDao.java】
package com.HigginCui.annotation;
public interface PersonDao {
public void savePerson();
}
【PersonDaoImpl.java】
package com.HigginCui.annotation; import org.springframework.stereotype.Repository;
/*
* @Repository("personDao")相当于
* <bean id="personDao" class="......PersonDaoImpl"></bean>
*/
@Repository("personDao")
public class PersonDaoImpl implements PersonDao{
public void savePerson() {
System.out.println("save Person...");
}
}
【PersonService.java】
package com.HigginCui.annotation;
public interface PersonService {
public void savePerson();
}
【PersonServiceImpl.java】
package com.HigginCui.annotation; import javax.annotation.Resource;
import org.springframework.stereotype.Service; @Service("personService")
public class PersonServiceImpl implements PersonService{
@Resource(name="personDao")
private PersonDao personDao;
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
@Override
public void savePerson() {
this.personDao.savePerson();
}
}
【PersonAction.java】
package com.HigginCui.annotation; import javax.annotation.Resource;
import org.springframework.stereotype.Controller; @Controller("personAction")
public class PersonAction {
@Resource(name="personService")
private PersonService personService; public void setPersonService(PersonService personService) {
this.personService = personService;
} public void savePerson(){
this.personService.savePerson();
}
}
【applicationContext.xml】
<?xml version= "1.0" encoding ="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- 把一个类放入到Spring容器中,该类就是一个component,此时不需要声明对应的bean -->
<context:component-scan base-package="com.HigginCui.annotation"></context:component-scan>
</beans>
【testPerson.java】
save Person...
12_注解04_注解实现Action调用Service,Service调用Dao的过程的更多相关文章
- Myeclipse插件快速生成ssh项目并配置注解 在action层注入service的超详细过程
最近发现,我对于ssh的 自动注入配置 还是不熟悉,于是整理了一下 终于做了一个 简单的 注入配置出来. 以前都是在applicationContext.xml 里面这样配 <bean id=& ...
- spring注解@service("service")括号中的service有什么用
相当于 xml配置中得 bean id = service 也可以不指定 不指定相当于 bean id = com. service.service 就是这个类的全限定名 好处是:同一个接口可以有多个 ...
- Spring中@Component注解,@Controller注解详解
在使用Spring的过程中,为了避免大量使用Bean注入的Xml配置文件,我们会采用Spring提供的自动扫描注入的方式,只需要添加几行自动注入的的配置,便可以完成 Service层,Controll ...
- JavaEE开发之Spring中的条件注解组合注解与元注解
上篇博客我们详细的聊了<JavaEE开发之Spring中的多线程编程以及任务定时器详解>,本篇博客我们就来聊聊条件注解@Conditional以及组合条件.条件注解说简单点就是根据特定的条 ...
- Spring普通类/工具类获取并调用Spring service对象的方法
参考<Spring普通类获取并调用Spring service方法>,网址:https://blog.csdn.net/jiayi_0803/article/details/6892455 ...
- Spring_day02--课程安排_Spring的bean管理(注解)(注解创建对象/注入属性、配置文件和注解混合使用)
Spring_day02 上节内容回顾 今天内容介绍 Spring的bean管理(注解) 注解介绍 Spring注解开发准备 注解创建对象 注解注入属性 配置文件和注解混合使用 AOP概念 AOP原理 ...
- spring常用的一些注解以及注解注入总结
常用的spring注解有如下几种: @Controller@Service@Autowired@RequestMapping@RequestParam@ModelAttribute@Cacheable ...
- Spring的注解@Qualifier注解
@Qualifier注解了,qualifier的意思是合格者,通过这个标示,表明了哪个实现类才是我们所需要的,我们修改调用代码,添加@Qualifier注解,需要注意的是@Qualifier的参数名称 ...
- java中Action层、Service层和Dao层的功能区分
Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO只 ...
随机推荐
- 12款有助于简化CSS3开发的工具
网站开发者能通过CSS3为网站设计增添很多时尚元素,CSS3 对CSS规范做了很大的改进.现在,本文将介绍12款有助于简化CSS3开发的工具. 1.CSS3 Pie: 允许在IE上使用CSS3绝大部 ...
- 查看Linux下*.a库文件中文件、函数、变量
查看Linux下*.a库文件中文件.函数.变量等情况在Linux 下经常需要链接一些 *.a的库文件,那怎么查看这些*.a 中包 含哪些文件.函数.变量: 1. 查看文件:ar -t xxx.a 2. ...
- storm出现的背景
storm出现的背景 互联网从诞生的第一时间起,对世界的最大改变就是让信息能够实时交互,从而大大加速了各个环节的效率.正因为大家有对信息实时响应.实时交互的需求,所以软件行业除了个人操作系统之外,数 ...
- advanced dom scripting dynamic web design techniques Part One DOM SCRIPTING IN DETAIL CHAPTER 1 DO IT RIGHT WITH BEST PRACTICES
You’re excited; your client is excited. All is well. You’ve just launched the client’s latest websit ...
- nyoj 282 You are my brother
You are my brother 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Little A gets to know a new friend, Litt ...
- java中通过反射获取方法并且调用(getMethod和invoke深入)实践
为了支持业务的快速变更,往往采用可配置的方式,将业务逻辑的处理部分配置在数据库中或者XMl文件里.配置什么,如何配置才更灵活,That's a problem. 以数据库配置为例(xml相同),在数据 ...
- [置顶] 单机版hadoop实例安装
目标:运行单机版hadoop http://localhost:50030mapredule监控界面 http://localhost:50070HDFS监控页面 -->安装linux系统 -- ...
- 【面试虐菜】—— Oracle中CHAR、VARCHAR的区别
1.CHAR. CHAR存储定长数据很方便,CHAR字段上的索引效率级高,比如定义char(10),那么不论你存储的数据是否达到了10个字节,都要占去10个字节的空间,不足的自动用空格填充,所以在读取 ...
- [微信小程序] 终于可以愉快的使用 async/await 啦
[小程序] 终于可以愉快的使用 async/await 啦 这篇文章主要是想说一下 怎么在微信小程序中使用async/await从而逃离回调地狱 背景 最近一直在搞微信小程序 用的语言是TypeScr ...
- 谷歌Flash不是最新版
http://www.adobe.com/support/flashplayer/debug_downloads.html