SSH采用annotation注入

一 标注:Dao 和 Service

标注dao:

@Repository("personDao")
public class PersonDaoImpl extends BaseHibernateDaoSupport implements PersonDao{

 

标注service:

@Repository("personService")
public class PersonServiceImpl implements PersonService {

 

 

二、注入dao和service

注入dao:

@Resource(name="personDao")
 private PersonDao personDao;

(不再需要getter和setter)

 

注入service:

@Resource(name="personService")
 private PersonService personService;

(不再需要getter和setter)

 

三、标注action

action的annotation:

@Controller @Scope("prototype")
@Results({
 @Result(name="save",location="/success.jsp")
})

public class PersonAction extends ActionSupport

 

 

需要注意的是:使用标注了,还需要在applicationContext.xml文件里面进行配置启动扫描

   具体配置如下:

         <context:annotation-config/>

    <!--  配置你需要扫描的package  红色的地方根据自己的包名填写-->

         <context:component-scan base-package="org.jxlg.sence.dao.impl,org.jxlg.sence.service.impl"/>

 

这样我们只需要在配置文件配置数据源,和基本的类了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值