刚开始学,spring
bean.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: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/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="com"></context:component-scan>
<bean id="us" class="com.user.user">
<property name="name" value="huangbaohua"></property>
<property name="age" value="23"></property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=us"></property>
<property name="username" value="lianer"></property>
<property name="password" value="lianer"></property>
</bean>
<bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.user.user</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialec">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernae.show_sql">true</prop>
</props>
</property>
</bean>
</beans>
serverDAOImple:
package com.servserdao.imple;
import javax.annotation.Resource;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import com.serverDAO.serverDAO;
import com.user.user;
@Component("u")
public class serverdaoimple implements serverDAO{
private SessionFactory sessionfactory;
private user user;
@Override
public void add(user u) {
Session s = sessionfactory.openSession();
s.beginTransaction();
s.save(user);
s.getTransaction().commit();
}
public SessionFactory getSessionfaction() {
return sessionfactory;
}
@Resource
public void setSessionfaction(SessionFactory sessionfactory) {
this.sessionfactory = sessionfactory;
}
}
user:
package com.user;
public