类库:在附件中。
EventDao是业务接口,EventDaoImpl是其实现类。
java 代码
- public interface EventDao {
- Event testEvent();
- }
-
- public class EventDaoImpl extends HibernateDaoSupport implements EventDao {
-
- public Event testEvent() {
- Event e = (Event) getHibernateTemplate().get(Event.class, 1l);
- return e;
- }
- }
java 代码
- public class AppContext {
-
-
-
-
- public static void main(String[] args) {
-
-
- AppContext ac = new AppContext();
- ac.initContext();
- }
-
- public void initContext() {
-
-
-
-
-
- ApplicationContext context = new ClassPathXmlApplicationContext(
- new String[] { "application-context.xml" });
-
-
-
- EventDao eventDao = (EventDao) context.getBean("myEventDao");
-
- Event e = eventDao.testEvent();
-
- System.out.println(e.getTitle() + ", " + e.getDate().toLocaleString());
- }
- }
hibernate-entities.xml
xml 代码
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <mapping class="com.james.business.modle.domain.Event" />
- </session-factory>
- </hibernate-configuration>
application-context.xml
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"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
-
- <bean id="myDataSource"
- class="org.apache.commons.dbcp.BasicDataSource"
- destroy-method="close">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url"
- value="jdbc:mysql://10.1.1.2:3306/test" />
- <property name="username" value="test" />
- <property name="password" value="test" />
- </bean>
-
- <bean id="mySessionFactory"
- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="dataSource" ref="myDataSource" />
-
-
-
-
-
<!---->- <property name="configLocations">
- <list>
- <value>classpath*:/hibernate-entities.xml</value>
- </list>
- </property>
- <property name="configurationClass"
- value="org.hibernate.cfg.AnnotationConfiguration" />
- <property name="hibernateProperties">
- <value>
- hibernate.dialect=org.hibernate.dialect.MySQLDialect
- </value>
- </property>
- </bean>
-
- <bean id="myEventDao"
- class="com.james.business.modle.dao.impl.EventDaoImpl">
- <property name="sessionFactory" ref="mySessionFactory" />
- </bean>
-
- </beans>
- 大小: 86.8 KB
分享到:
相关推荐
spring + struts + hibernate sample spring + struts + hibernate sample spring + struts + hibernate sample spring + struts + hibernate sample
Struts 2+Hibernate+Spring整合开发技术详解sample.pdf
spring+hibernate+struts 范例代码
Spring hibernate jpa Project sample
spring3.0 jpa hibernate 完整的工程项目包. eclipse 3.5 导入 说明: http://blog.csdn.net/remote_roamer/archive/2010/02/03/5285904.aspx
一个简单的JSF整合Spring、Hibernate等框架的例子,有助于深入学习的JSF开发!
spring boot jsp mvc jpa hibernate mysql 示例 sample
hibernate-4.3.10+spring 4.1.7+struct 2.3.24搭建的环境以及所遇需要的lib包 附带一个注册的小sample macOS下亲测可用
本工程基于以下框架实现工作流的实例. struts+spring+hibernate3.0+jbpm3.1.4,可以tomcat下运行,可通过图形模式发布工程,配置了在网页显示jbpm流程图的标签文件。
spring-javaconfig-sample, Spring MVC/Spring Data JPA/Hibernate的spring JavaConfig示例 spring-配置示例自 spring 3.0以来,JavaConfig特性被包含在核心 spring 模块中。 因此Java开发人员可以将 spring bean...
Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development....
Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development....
这是 《使用 Spring Data JPA 简化 JPA 开发》的sample code。原文在 http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-jpa/index.html
Database interaction using Spring and Hibernate/JPA- Spring Data JPA- Spring Data MongoDB- Messaging, emailing and caching support- Spring Web MVC- Developing RESTful web services using Spring Web ...
[]样本启动Hibernateはじめに / /を元にしたDDDサンプル実装です。ベーシックな基盘はから流用しています。フレームワークではないので,Spring Bootを利用するプロジェクトを立ち上げる际に元テンプレートとして...
服务器存储依赖于带有 Hibernate/JPA api 的内存 H2 数据库。 项目是用maven构建的。 无需单独下载 extjs、bootstrap 或 jquery。 所有依赖项都由 maven 管理。 只需运行“mvn package”并将“sample.war”从项目的...
该框架是Spring+hibernate+struts+sql2005搭建成,对数据做了国际化。 框架中提供了sample,供大家理解学习该框架,如果大家对框架有任何问题或者觉得有更好的实现方式也可以Email给我,大家互相学习。 MSN:...
修改hibernate.properties对应的参数 运行测试: com/jview/test/testMapping.java com/sample/TestCcar.java,不含spring com/sample/TestCcarSpring.java,含spring com/sample/TestCcarSpring2.java,含spring并与...