67,513
社区成员
发帖
与我相关
我的任务
分享
@SuppressWarnings("serial")
@Entity
@Table(name="admin_table")
public class Admin {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@Column(name="user_name", length=30)
private String userName;
@Column(name="password", length=30)
private String password;
public Admin(){}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:/hibernate.cfg.xml">
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="userService" class="com.newsDemo.service.impl.UsersServiceImpl"/>
<bean id="adminService" class="com.newsDemo.service.impl.AdminServiceImpl"/>
<bean id="newsService" class="com.newsDemo.service.impl.NewsServiceImpl"/>
<bean id="userDao" class="com.newsDemo.dao.impl.UsersDaoImpl"/>
<bean id="adminDapo" class="com.newsDemo.dao.impl.AdminDaoImpl"/>
<bean id="newsDao" class="com.newsDemo.dao.impl.NewsDaoImpl"/>
<bean id="beginningAction" class="com.newsDemo.action.BeginningAction"/>
<bean id="newsAction" class="com.newsDemo.action.NewsAction"/>
<bean id="adminAction" class="com.newsDemo.action.AdminAction"/>
</beans>
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Hibernate配置文件的DTD信息 -->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- hibernate- configuration是连接配置文件的根元素 -->
<hibernate-configuration>
<session-factory>
<!-- 指定连接数据库所用的驱动 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 指定连接数据库的url,hibernate连接的数据库名 -->
<property name="connection.url">jdbc:mysql://localhost:3306/News</property>
<!-- 指定连接数据库的用户名 -->
<property name="connection.username">root</property>
<!-- 指定连接数据库的密码 -->
<property name="connection.password">root</property>
<!-- 指定连接池里最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 指定连接池里最小连接数 -->
<property name="hibernate.c3p0.min_size">1</property>
<!-- 指定连接池里连接的超时时长 -->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 指定连接池里最大缓存多少个Statement对象 -->
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 指定数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 二级缓存
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.OSCacheProvider</property>
-->
<!-- 根据需要自动创建数据表 -->
<property name="hbm2ddl.auto">create</property>
<!-- 显示Hibernate持久化操作所生成的SQL -->
<property name="show_sql">true</property>
<!-- 将SQL脚本进行格式化后再输出 -->
<property name="hibernate.format_sql">true</property>
<!-- 罗列所有的映射文件 -->
<mapping resource="com.newsDemo.po.Admin"/>
<mapping resource="com.newsDemo.po.News"/>
<mapping resource="com.newsDemo.po.NewClass"/>
<mapping resource="com.newsDemo.po.Users"/>
</session-factory>
</hibernate-configuration>