81,092
社区成员
发帖
与我相关
我的任务
分享
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean-->
<bean id="customerService" lazy-init="default" autowire="default" dependency-check="default">
<property name="target">
<bean class="com.sshtest.service.impl.CustomerServiceImpl" lazy-init="default" autowire="default" dependency-check="default">
<property name="customerDAO">
<ref bean="CustomerDAO" />
</property>
</bean>
</property>
</bean>
</beans>
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:hp">
</property>
<property name="username" value="hp"></property>
<property name="password" value="hp"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/test/hibernate/entity/Customer.hbm.xml</value>
</list>
</property>
</bean>
<bean id="CustomerDAO" class="com.sshtest.dao.impl.CustomerDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
public class CustomerDAOImpl extends HibernateDaoSupport implements CustomerDAO {
public void delete(Integer id) {
// TODO Auto-generated method stub
this.getHibernateTemplate().delete(this.getCustomerById(id));
}
public void save(Customer cus) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(cus);
}
public void update(Integer id) {
// TODO Auto-generated method stub
this.getHibernateTemplate().update(this.getCustomerById(id));
}
public Customer getCustomerById(Integer id) {
// TODO Auto-generated method stub
return (Customer) this.getHibernateTemplate().get(Customer.class, id);
}
public Customer getCustomerByLoginId(String loginId) {
// TODO Auto-generated method stub
String hql="from Customer c where c.loginId = ?";
List <Customer> list=this.getHibernateTemplate().find(hql);
Customer cus = list.get(0);
return cus;
}
}
public class CustomerServiceImpl implements CustomerService {
private CustomerDAO dao;
public void addUser(Customer user) {
// TODO Auto-generated method stub
dao.save(user);
}
public boolean checkLogin(String loginId, String pass) {
// TODO Auto-generated method stub
Customer cus=dao.getCustomerByLoginId(loginId);
if(cus!=null && cus.getPassword().equals(pass))
return true;
return false;
}
public Customer getCustomer(Integer id) {
// TODO Auto-generated method stub
return dao.getCustomerById(id);
}
public void setCustomerDao(CustomerDAO dao) {
// TODO Auto-generated method stub
this.dao=dao;
}
}
<bean id="customerService" class="com.sshtest.service.impl.CustomerServiceImpl" >
<property name="CustomerDAO">
<ref bean="CustomerDAO" />
</property>
</bean>
<bean id="customerService" lazy-init="default" autowire="default" dependency-check="default">
</bean>