hibernate基本框架及配置
来源:互联网 发布:以太网地址和mac地址 编辑:程序博客网 时间:2024/05/18 01:01
1.hibernate要用到的jar包:
2.hibernate的基本框架(jdk用1.7版本的,不能用1.8版本的):
2.applicationContext.xml的配置:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd"><!-- 引入properties文件 --><context:property-placeholder location="classpath*:/db.properties" /><context:annotation-config /><!-- 对指定的包进行组件扫描 --><context:component-scan base-package="com.courseManagement" /><!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 --><context:component-scanbase-package="com.courseManagement.hibernate,com.courseManagement.Controller"><context:exclude-filter type="annotation"expression="org.springframework.web.bind.annotation.ControllerAdvice" /></context:component-scan><!-- 定义数据库连接池数据源bean --><context:annotation-config /><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="${hibernate.driverName}" /><property name="url" value="${hibernate.url}" /><property name="username" value="${hibernate.username}" /><property name="password" value="${hibernate.password}" /></bean><!-- 定义Hibernate Session工厂 --><bean id="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="hibernateProperties"><props><prop key="hibernate.dialect">${hibernate.dialect}</prop><prop key="hibernate.show_sql">${hibernate.show_sql}</prop><prop key="hibernate.format_sql">${hibernate.format_sql}</prop><prop key="hibernate.hbm2ddl.auto">update</prop><prop key="current_session_context_class">thread</prop></props></property><property name="packagesToScan" value="com.courseManagement.hibernate" /><!-- 如果多个,用“,”分隔 --></bean><!-- 定义事务 --><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- 配置 Annotation 驱动,扫描@Transactional注解的类定义事务 --><tx:annotation-driven transaction-manager="transactionManager"proxy-target-class="true" /></beans>
3.db.properties配置:
hibernate.driverName=com.mysql.jdbc.Driverhibernate.url=jdbc:mysql://localhost:3306/coursemanagementhibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.username=roothibernate.password=roothibernate.maxIdle=255hibernate.minIdle=2hibernate.maxWait=120000hibernate.show_sql=truehibernate.format_sql=true
4.spring-mvc.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"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"><!-- 自动扫描该包,Spring MVC 会将包下用 @Controller 注解的类注册为 Spring 的 controller --><context:component-scan base-package="com.courseManagement.Controller" /><!-- 设置默认配置方案 --><mvc:annotation-driven /><!-- 视图解析器 --><bean id="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 执行完action后会返回xxx,xxx会和下面的property组合,形成跳转页面的路径 --><property name="prefix" value="" /><property name="suffix" value=".jsp" /></bean></beans>
5.web.xml配置:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>courseManagerment</display-name><!-- 配置 Spring 核心监听器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 指定 Spring 的配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- 定义 Spring MVC 前端控制器 --><servlet><servlet-name>springMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- 为 DispatcherServlet 建立映射 --><servlet-mapping><servlet-name>springMVC</servlet-name><url-pattern>/</url-pattern></servlet-mapping><listener><listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener><!-- 编码过滤器 --><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- 控制Session的开关 --><filter><filter-name>openSession</filter-name><filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>openSession</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- 设置首页 --><welcome-file-list><welcome-file>managerLogin.jsp</welcome-file></welcome-file-list></web-app>
6.com.courseManagement.hibernate包里面写的实际上是entity。
阅读全文
0 0
- hibernate基本框架及配置
- SSH:Hibernate框架(关系映射及基本配置)
- Hibernate基本配置及操作
- hibernate框架基本搭建及使用
- Struts2框架之基本概述及配置
- Spring框架之基本概述及配置
- hibernate基本介绍及基本配置(一)
- SSH:Hibernate框架(Hibernate继承关系映射及配置)
- hibernate框架基本的作用及用法【1】
- SpringMVC+Hibernate+Junit4+json基本框架近乎0配置
- SpringMVC+Hibernate+Junit4+json基本框架近乎0配置
- Hibernate基本框架创建
- Hibernate框架基础知识第二第二天Hibernate的重要配置 1.基本配置天
- Hibernate学习笔记(二)【标识符及基本级联配置】
- Hibernate教程01_Hibernate的HelloWorld及基本配置
- Hibernate学习笔记(二)【标识符及基本级联配置】
- Hibernate(5.2.10)快速入门 (一) 初识Hibernate、框架搭建、xml基本配置
- Hibernate 基本配置
- 从m中取出n个全组合
- RCNN详解
- Android 面试题汇总
- String源码总结
- Java 字节流 复制MP3
- hibernate基本框架及配置
- 正则表达式匹配(Regular Expression Matching)
- 建立Win32 Console Project/MFC项目时会出现"LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏"的错误。
- 147. Insertion Sort List(链表的插入排序)
- hdu1502 Regular Words 【dp+高精度加法】
- 中国铁路率先实现刷脸进站 化妆戴美瞳都能认出来
- 百度西雅图开设AI实验室 总裁张亚勤称AI是时代变革之能
- 速度快1000倍!DeepMind更新WaveNet用于Google助手
- String类以及常用的方法