一 标注: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"/>
这样我们只需要在配置文件配置数据源,和基本的类了