spring常用的标签@Repository,@controller,@service
来源:互联网 发布:usb6009数据采集卡 编辑:程序博客网 时间:2024/06/04 04:43
在annotaion配置注解中用@Component来表示一个通用注释用于说明一个类是一个spring容器管理的类。即就是该类已经拉入到spring的管理中了。而@Controller, @Service, @Repository是@Component的细化,这三个注解比@Component带有更多的语义,它们分别对应了控制层、服务层、持久层的类。
@Repository标签是用来给持久层的类定义一个名字,让Spring根据这个名字关联到这个类。
例如:
@Repository("userDao")
public class UserDaoImpl implements UserDao{
........................................
}
声明了UserDaoImpl 在Spring容器中叫userDao这个名字。
@Service是用于服务层的IServiceImpl类文件,功能与@Repository类似。
另外标签:@Autowired 用来注入。
例如:
@Autowired
private UserDao userDao;
这样就注入进去了,相当于我们new了个实现类,我们就无需写setter方法了。
我们还得有配置文件进行配置:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.zxr.manager">
<context:include-filter type="regex" expression=".*DaoImpl"/>
<context:include-filter type="regex" expression=".*ServiceImpl"/>
</context:component-scan>
</beans>
这样就把com.zxr.manager包下的所有.*DaoImpl,.*ServiceImpl都注册关联到Spring容器中去了。
@Repository标签是用来给持久层的类定义一个名字,让Spring根据这个名字关联到这个类。
例如:
@Repository("userDao")
public class UserDaoImpl implements UserDao{
........................................
}
声明了UserDaoImpl 在Spring容器中叫userDao这个名字。
@Service是用于服务层的IServiceImpl类文件,功能与@Repository类似。
另外标签:@Autowired 用来注入。
例如:
@Autowired
private UserDao userDao;
这样就注入进去了,相当于我们new了个实现类,我们就无需写setter方法了。
我们还得有配置文件进行配置:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.zxr.manager">
<context:include-filter type="regex" expression=".*DaoImpl"/>
<context:include-filter type="regex" expression=".*ServiceImpl"/>
</context:component-scan>
</beans>
这样就把com.zxr.manager包下的所有.*DaoImpl,.*ServiceImpl都注册关联到Spring容器中去了。
- spring常用的标签@Repository,@controller,@service
- spring @component,@service,@controller,@repository等标签
- Spring常用注解@Component、@Controller、@ Service、@ Repository......
- Spring的标注@Component,@Service,@Controller,@Repository
- spring的@Component,@Service,@Controller,@Repository注解
- spring mvc常用注解@Component @Controller @Service @Repository
- spring mvc常用注解@Component @Controller @Service @Repository
- spring mvc常用注解@Component @Controller @Service @Repository
- Spring注解@Repository、@Service、@Controller
- spring注解:@Repository、@Service、@Controller
- Spring @Component、@Repository、@Service、@Controller
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring中注解@Controller@Service@Repository@Component的区别
- Spring的注解类(@Component、@Repository、@Service、@Controller )
- spring 中四种注解@controller,@service,@repository,@component的区别
- spring的@compont和@service以及@controller,@repository区别
- Spring 中@Component @Controller @Service @Repository注解的意思
- 数据中心:选择外包服务的八大技巧
- C#学习之接口
- Ant build.xml的创建(三)
- reviewboard的LDAP认证的配置
- js二级联动的实现
- spring常用的标签@Repository,@controller,@service
- 设计模式学习-----抽象工厂模式
- Apache--SSI 服务器端包含
- shell ls结果赋给变量
- String.split()方法的详解
- 计算给定两个日期间工作日
- jdk
- postgresql 不错的全文检索资料
- 企业实时通信解决方案