首页 > 代码库 > ssh 注解写法
ssh 注解写法
弄了半天 (好久哦)
首先 applicationContext-db.xml
<?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/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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate/hibernate.cfg.xml</value> </property> </bean> 事务管理 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <tx:advice transaction-manager="transactionManager" id="tx"> <tx:attributes> <tx:method name="save*" read-only="false"/> <tx:method name="update*" read-only="false"/> <tx:method name="delete*" read-only="false"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* wl.oa.service.impl.*.*(..))" id="perform"/> <aop:advisor advice-ref="tx" pointcut-ref="perform"/> </aop:config> --> <!-- 导入类扫描的注解解析器和事务的注解解析器 --> <context:component-scan base-package="wl.oa"></context:component-scan> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate/hibernate.cfg.xml</value> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> </beans>
package wl.oa.dao;import wl.oa.dao.base.BaseDao;import wl.oa.domain.Person;public interface PersonDao<T> extends BaseDao<T>{ //public void savePerson(Person person);}
package wl.oa.dao.impl;import javax.annotation.Resource;import org.springframework.orm.hibernate3.HibernateTemplate;import org.springframework.stereotype.Repository;import wl.oa.dao.PersonDao;import wl.oa.dao.base.impl.BaseDaoImpl;import wl.oa.domain.Person;@Repository("personDao")public class PersonDaoImpl extends BaseDaoImpl<Person> implements PersonDao<Person>{// @Resource(name="hibernateTemplate")// private HibernateTemplate hibernateTemplate;// public void savePerson(Person person) {// // TODO Auto-generated method stub// this.hibernateTemplate.save(person);// }}
package wl.oa.service;import wl.oa.domain.Person;import wl.oa.service.base.BaseService;public interface PersonService<T> extends BaseService<T>{ //public void savePerson(Person person);}
package wl.oa.service.impl;import javax.annotation.Resource;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import wl.oa.dao.PersonDao;import wl.oa.domain.Person;import wl.oa.service.PersonService;import wl.oa.service.base.impl.BaseServiceImpl;@Service("personService")public class PersonServiceImpl extends BaseServiceImpl<Person> implements PersonService<Person>{ // @Resource(name="personDao")// PersonDao personDao; // public PersonDao getPersonDao() {// return personDao;// }//// public void setPersonDao(PersonDao personDao) {// this.personDao = personDao;// }// @Transactional(readOnly=false)// public void savePerson(Person person) {// // TODO Auto-generated method stub// this.personDao.savePerson(person);// }}
ssh 注解写法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。