笔记48 Spring+SpringMVC+Hibernate整合
搭建Spring+SpringMVC+Hibernate的框架的思路如下:
1、创建Maven项目,按需映入Maven包依赖。
2、搭建Spring:配置Spring对控件层Bean的注入。
3、搭建Hibernate:配置数据源,配置SessionFactory,配置事务。
4、映入SpringMVC:配置SpringMVC配置信息。
5、配置web.xml容器
6、测试三个框架的整合:。
一、创建Maven项目、导入依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.li</groupId>
<artifactId>SSHDemo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SSHDemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.7.RELEASE</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations -->
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.3.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.3.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/mchange-commons-java -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>mchange-commons-java</artifactId>
<version>0.2.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.2.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.transaction/jboss-transaction-api_1.2_spec -->
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml/classmate -->
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.22.0-GA</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss/jandex -->
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.0.5.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml/classmate -->
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/antlr/antlr -->
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.8.12</version>
</dependency> </dependencies>
<build>
<finalName>SSHDemo</finalName>
</build>
</project>
二、配置web.xml
1.配置Spring的IOC容器
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在src/main/resources下新建文件config,将所有的配置文件放在里面。创建spring配置文件applicationContext.xml
2.配置SpringMVC的核心控制器
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
在config目录中创建SpringMVC的配置文件springmvc.xml
3.配置编码方式(过滤器),这个过滤器必须放在所有过滤器前。
<filter>
<filter-name>characterEncodingFilter</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>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4.为了使用SpringMVC框架实现REST,需配置HiddenHttpMethodFilter。
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_1529217958650">
<!-- 配置Spring IOC 容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 配置Springmvc的核心控制器 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- 配置编码方式过滤器,且必须配置在所有的过滤器最前面 -->
<filter>
<filter-name>characterEncodingFilter</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>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 为了使用SpringMVC框架实现REST,需配置HiddenHttpMethodFilter -->
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>
三、配置SpringMVC
1.配置自动扫描的包
<context:component-scan base-package="com.Spittr.dao.impl"
use-default-filters="false">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
2.配置视图解析器
应用中所有的视图即JSP文件都放入WEB-INF下的view文件夹中。
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>
3.配置静态资源
<mvc:default-servlet-handler/>
4.配置注解
<mvc:annotation-driven></mvc:annotation-driven>
springmvc.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" 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
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 配置自动扫描的包 -->
<context:component-scan base-package="com.Spittr.dao.impl"
use-default-filters="false">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan> <!-- 配置视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>
<!-- 配置静态资源 -->
<mvc:default-servlet-handler/>
<!-- 配置注解 -->
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
四、配置Spring
1.配置自动扫描的包
包含Controller和ControllerAdvice注解的bean交给SpringMVC来扫描,Spring就不再扫描了,所以要把这两个注解排除在外。
<context:component-scan base-package="com.Spittr"
use-default-filters="false">
<!-- 去除由Springmvc负责扫描的注解 -->
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
2.配置数据源
数据源配置文件:db.properties,也放在config文件夹中。
jdbc.user=root
jdbc.password=123456
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc\:mysql\://localhost\:3306/spittr
<context:property-placeholder location="classpath:/config/db.properties" />
3.配置DataSource,使用c3p0连接池。
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource">
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
</bean>
五、配置Hibernate
1.配置SeeionFactory
<bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
id="sessionFactory"> </bean>
在SessionFactory中需要添加以下三个property:
1.1.配置数据源
<property name="dataSource" ref="dataSource"></property>
1.2.配置实体包(pojo)
<property name="PhysicalNamingStrategy">
<bean class="org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl"></bean>
</property>
<property name="packagesToScan" value="com.Spittr.entity"></property>
1.3.配置Hibernate的常用属性
<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>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
2.配置hibernate的事务管理器
<bean class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
applicationContext.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-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <!-- 配置自动扫描的包 -->
<context:component-scan base-package="com.Spittr"
use-default-filters="false">
<!-- 去除由Springmvc负责扫描的注解 -->
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan> <!-- 配置数据源 -->
<context:property-placeholder location="classpath:/config/db.properties" /> <!-- 配置DataSource -->
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource">
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
</bean> <!-- 配置SeeionFactory -->
<bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
id="sessionFactory">
<!-- 配置数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 配置实体包(pojo) -->
<property name="PhysicalNamingStrategy">
<bean
class="org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl"></bean>
</property>
<property name="packagesToScan" value="com.Spittr.entity"></property> <!-- 配置Hibernate的常用属性 -->
<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>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean> <!-- 配置hibernate的事务管理器 -->
<bean class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
六、测试
1.测试是否能得到配置文件applicationContext.xml
private ApplicationContext ctx = null;
ctx = new ClassPathXmlApplicationContext("/config/applicationContext.xml");
System.out.println(ctx);
2.测试是否能获取数据源
DataSource dataSource = ctx.getBean(DataSource.class);
System.out.println(dataSource.getConnection().toString());
3.测试Hibernate中SessionFactory是否能获取
SessionFactory sessionFactory = ctx.getBean(SessionFactory.class);
System.out.println(sessionFactory);
4.对数据库进行操作
首先创建实体类:Spitter.java
package com.Spittr.entity; import java.io.Serializable; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table; @Entity
@Table(name = "spitter")
public class Spitter implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
String username;
String password;
String email; public Spitter() {
// TODO Auto-generated constructor stub
} public Spitter(String username, String password, String email) {
super();
this.username = username;
this.password = password;
this.email = email;
} public int getId() {
return id;
} public void setId(int 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;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
}
}
测试
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Spitter spitter = new Spitter("222qqqq222", "123123", "123213");
session.save(spitter);
transaction.commit();
session.close();
testSSH.java
package com.Spittr.test; import java.sql.SQLException; import javax.sql.DataSource;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException; import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.Spittr.entity.Spitter; public class testSSH { private ApplicationContext ctx = null; @Test
public void testDataSource() throws SQLException, SecurityException, RollbackException, HeuristicMixedException,
HeuristicRollbackException, SystemException { ctx = new ClassPathXmlApplicationContext("/config/applicationContext.xml");
System.out.println(ctx);
// System.out.println();
// 测试数据源
DataSource dataSource = ctx.getBean(DataSource.class);
System.out.println(dataSource.getConnection().toString()); // 测试SessionFactory
SessionFactory sessionFactory = ctx.getBean(SessionFactory.class);
System.out.println(sessionFactory); // 测试操作数据库表(session)
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Spitter spitter = new Spitter("222qqqq222", "123123", "123213");
session.save(spitter);
transaction.commit();
session.close(); } }
七、配置过程中遇到的问题
1.classpath的相关问题
前缀 | 说明 |
---|---|
classpath | 优先本项目class路径查找,没有的话依次在其他jar包中class路径查找,找到第一个匹配的为止 |
classpath* | 加载到所有class路径下的配置文件,包括jar包的class路径下,最终加载所有匹配的 |
file | 通过URL加载,来源为文件系统(注意文件读取权限) |
http | 通过URL加载,来源为网络 |
在maven项目中,classpath对应的目录是Webapp\target\classes,也就是把配置文件都放入src/main/resources目录下即可,本例中是把config文件夹放入src/main/resources中,所以在读取config中的配置文件时,所以才会使用classpath:/config/***形式。
2.hibernate的配置
org.hibernate.cfg.NamingStrategy接口允许你为数据库中的对象和schema 元素指定一个“命名标准”. 你可能会提供一些通过Java标识生成数据库标识或将映射定义文件中"逻辑"表/列名处理成"物理"表/列名的规则. 这个特性有助于减少冗长的映射定义文件。
但是在Hibernate到5.1的后,hibernate.ejb.naming_strategy将不再被支持,而是被替换成了两个属性:
- hibernate.physical_naming_strategy:隐式命名策略,使用此属性当我们使用的表或列没有明确指定一个使用的名称。
- hibernate.implicit_naming_strategy:物理命名策略,用于转换“逻辑名称”(隐式或显式)的表或列成一个物理名称。
①对于physical_naming_strategy有两个常用的配置:
- org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
- org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
对于PhysicalNamingStrategyStandardImpl有DefaultNamingStrategy的效果;对于SpringPhysicalNamingStrategy有
ImprovedNamingStrategy的效果。
②在sessionFactory的bean里配置。
<property name="PhysicalNamingStrategy">
<bean class="org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl"></bean>
</property>
或
<property name="ImplicitNamingStrategy">
<bean class="org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl" />
</property>
八、代码下载
https://github.com/lyj8330328/SSHDemo-Maven-Webapp
笔记48 Spring+SpringMVC+Hibernate整合的更多相关文章
- 框架篇:Spring+SpringMVC+hibernate整合开发
前言: 最近闲的蛋疼,搭个框架写成博客记录下来,拉通一下之前所学知识,顺带装一下逼. 话不多说,我们直接步入正题. 准备工作: 1/ IntelliJIDEA的安装配置:jdk/tomcat等..(本 ...
- spring+springmvc+hibernate整合遇到的问题
spring+springmvc+hibernate整合遇到的问题2016年10月20日 23:24:03 守望dfdfdf 阅读数:702 标签: ssh学习经历的异常exception异常框架更多 ...
- springmvc框架(Spring SpringMVC, Hibernate整合)
直接干货 model 考虑给用户展示什么.关注支撑业务的信息构成.构建成模型. control 调用业务逻辑产生合适的数据以及传递数据给视图用于呈献: view怎样对数据进行布局,以一种优美的方式展示 ...
- spring+springmvc+hibernate 整合
三大框架反反复复搭了很多次,虽然每次都能搭起来,但是效率不高.最近重新搭了一次,理顺了思路,整理了需要注意的地方,分享出来. 工具:Eclipse(jdk 1.7) spring和hibernate版 ...
- Spring MVC基础知识整理➣Spring+SpringMVC+Hibernate整合操作数据库
概述 Hibernate是一款优秀的ORM框架,能够连接并操作数据库,包括保存和修改数据.Spring MVC是Java的web框架,能够将Hibernate集成进去,完成数据的CRUD.Hibern ...
- Spring+SpringMvc+Hibernate整合记录
Spring+SpringMvc+Hibernate+Maven整合各大配置文件记录 1.Idea新建的Maven架构 2.Maven的对象模型的内容 <project xmlns=" ...
- spring+springmvc+hibernate整合实例
最近要弄一个自动化生成表及其实体对应的增删改查的框架,于是我想到了hibernate,hibernate就有根据实体自动建表,而且增删改查,都不需要想mybatis那样在xml文件中配置. 不过怎样让 ...
- spring+springMVC+hibernate整合
首先我们要知道hibernate五大对象:,本实例通过深入的使用这五大对象和spring+springMVC相互结合,体会到框架的好处,提高我们的开发效率 Hibernate有五大核心接口,分别是:S ...
- SSH(Spring SpringMVC Hibernate)框架整合
项目说明: 使用SSH(Spring SpringMVC Hibernate)框架整合添加部门功能 项目结构 1.导入依赖jar包 <!--单测--> <dependency&g ...
随机推荐
- 防止按钮重复点击的思路(js篇)
最直接的思路可能就是点击按钮后,按钮的事件绑定函数解绑,1s后重新绑定函数 <button id=</button> <script> btn.onclick = fun ...
- this 的指向问题
1.全局作用域或者普通函数中 this 指向全局对象 window ( 定时器里面的this 指向 window ) 1.1 console.log(this); // window 1.2 func ...
- opensns功能详解
<!DOCTYPE html> opensns功能详解 wmd-preview h1 { color: #0077bb; /* 将标题改为蓝色 */ } opensns功能详解 软件工程 ...
- 【教程】CentOS 7安装 最新版本Docker
博主最近需要安装Docker,步骤如下: Docker安装官方地址:https://docs.docker.com/install/linux/docker-ce/centos/ 以下命令都是在roo ...
- linux 虚拟机网卡配置
第一种虚拟机 我们常用的虚拟机vmware虚拟机 今天为了学习ngnix,所以配了两台虚拟机.一个centos7 ,一个redhat. 哇啦哇啦安装,so easy,对吧....我选择的是精简版 ...
- Codeforces 745E Hongcow Buys a Deck of Cards 状压DP / 模拟退火
题意:现在有n张卡片(n <= 16), 每一轮你可以执行两种操作中的一种.1:获得一张红色令牌和一张蓝色令牌.2:购买一张卡片(如果可以买的话),购买的时候蓝色卡片可以充当蓝色令牌,红色同理, ...
- Codeforces 1155F 状压DP
题意:给你一张图,问最少保留多少条边,使得这张图是边双联通分量. 思路:如果一个点集中的点已经是边双联通分量,那么从这个点集中的点x出发,经过若干个不是点集中的点,回到点集中的点y(x可能等于y),那 ...
- Delphi DBgrid 动态点击事件
错误的写法: DBGrid1CellClick(DBGrid1.Columns[ DBGrid1.DataSource.DataSet.RecNo ]); //执行点击事件 正确的写法: DBGrid ...
- 使用Vue和djangoframwork完成登录页面构建 001
使用Vue和djangoframwork完成登录页面构建 001 环境的搭建 首先,我在我的电脑的F盘创建了一个文件夹 forNote,进入到这个文件夹中 F:\forNote> vue环境的搭 ...
- 网格图必经点+dfs——cf1214D
先正着走一次把所有可行路径标记出来,然后倒着走两条路径,一条是能向下就向下的路径,另一条能向右就向右. 如果这两条路径相交,那么(1,1)-(n,m)路径上比有个必经点,把这个必经点封上,答案是1,如 ...