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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<!-- DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="username" value="root">
</property>
<property name="password" value="root">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/learningforum?useUnicode=true&characterEncoding=utf8">
</property>
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
</bean>
<!-- 定义SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- 指定db连接参数 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 指定映射描述 -->
<property name="annotatedClasses">
<list>
<value>future.ok.forum.model.User</value>
<value>future.ok.forum.model.Lesson</value>
<value>future.ok.forum.model.LessonChild</value>
<value>future.ok.forum.model.LessonChildSon</value>
<value>future.ok.forum.model.UserPost</value>
<value>future.ok.forum.model.UserPro</value>
<value>future.ok.forum.model.UserLesson</value>
<value>future.ok.forum.model.UserNews</value>
<value>future.ok.forum.model.UserPostChild</value>
<value>future.ok.forum.model.PostBrowse</value>
</list>
</property>
<!-- 指定框架参数 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<!-- 定义HibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean>
</beans>
package future.ok.forum.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="userpost")
public class UserPost {
private int userpostid;
private int userid;
private String userposttitle;
private String userpostvalue;
private java.util.Date timestamp;
private int browse;
private int comment;
@Id
public int getUserpostid() {
return userpostid;
}
public void setUserpostid(int userpostid) {
this.userpostid = userpostid;
}
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUserposttitle() {
return userposttitle;
}
public void setUserposttitle(String userposttitle) {
this.userposttitle = userposttitle;
}
public String getUserpostvalue() {
return userpostvalue;
}
public void setUserpostvalue(String userpostvalue) {
this.userpostvalue = userpostvalue;
}
public java.util.Date getTimestamp() {
return timestamp;
}
public void setTimestamp(java.util.Date timestamp) {
this.timestamp = timestamp;
}
public int getBrowse() {
return browse;
}
public void setBrowse(int browse) {
this.browse = browse;
}
public int getComment() {
return comment;
}
public void setComment(int comment) {
this.comment = comment;
}
}