1.hibernate译为“越冬”,指的是给java程序员带来春天,因为java程序员无需再关心各种sql了;

2.hibernate通过java类生成数据库表,通过操作对象来映射成SQL;

3.hibernate是真正意义上的ORM框架,因为他实现了对象(Object)---->关系(Relation)的映射(Mapping);

4.maven项目整体包结构(报错是eclipse发神经,不用管)

因为hibernate可以根据类生成表,所以只需创建数据库即可;

create database ssh;

该案例实现了一个用户拥有多部手机的关系

5.各种配置文件

(1)pom.xml

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xiaog</groupId>
<artifactId>testssh</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging> <dependencies>
<!-- spring+springmvc顶级依赖包,包含spring-webmvc、spring-aop、spring-beans、
spring-context、spring-core、spring-jcl、spring-expression、spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency> <!-- spring-aop所依赖的静态代理 ,
使用aop方式管理事务,在service方法执行前开启事务,
方法执行后提交事务,方法执行失败回滚事务-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.0</version>
</dependency> <!-- 使用jdbcTemplate中的事务实现 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency> <!-- 数据库方面 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency> <!-- orm框架 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.2.Final</version>
</dependency> <!-- spring对于orm框架的支持 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.2.4.RELEASE</version>
</dependency> <!-- Logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.logback-extensions</groupId>
<artifactId>logback-ext-spring</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.12</version>
</dependency> <!-- jsp需要 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies> <build>
<defaultGoal>compile</defaultGoal>
<plugins>
<!-- maven插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>9999</port>
<path>/testssh</path>
<uriEncoding>UTF-8</uriEncoding>
<finalName>testssh</finalName>
<server>tomcat7</server>
</configuration>
</plugin>
<!-- <plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</plugin> -->
</plugins>
</build>
</project>

pom.xml

(2)spring-context.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"
default-autowire="byName" default-lazy-init="true">
<description>Spring公共配置 </description>
<!-- 1.扫描包: @Repository @Service @Autowired @Resource -->
<context:component-scan base-package="com.xiaog.dao,com.xiaog.service" /> <!-- 2.加载配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" /> <!-- 3.配置连接池 :druid连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 初始化连接数量 -->
<property name="initialSize" value="5" />
<!-- 最大连接数 -->
<property name="maxActive" value="100" />
<!-- 最小连接数 -->
<property name="minIdle" value="5" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="120000" />
<!-- 超过时间限制是否回收 -->
<property name="removeAbandoned" value="true" />
<!-- 超过时间限制多长 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="120000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<!-- 用来检测连接是否有效的sql,要求是一个查询语句 -->
<property name="validationQuery" value="SELECT 1" />
<!-- 申请连接的时候检测 -->
<property name="testWhileIdle" value="true" />
<!-- 申请连接时执行validationQuery检测连接是否有效,配置为true会降低性能 -->
<property name="testOnBorrow" value="false" />
<!-- 归还连接时执行validationQuery检测连接是否有效,配置为true会降低性能 -->
<property name="testOnReturn" value="false" />
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
<property name="defaultAutoCommit" value="false" />
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat"/>
</bean> <!-- 4.spring集成hibernate -->
<!-- 配置hibernate的SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 注入数据源 相关信息看源码 -->
<property name="dataSource" ref="dataSource" />
<!-- 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">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 扫描hibernate注解配置的entity -->
<property name="packagesToScan" value="com.xiaog.entity" />
</bean> <!-- 5.配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <!-- 6.配置aop -->
<!-- 配置通知: 定位方法 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- 配置切面 -->
<aop:config>
<!-- 定位具体的类:完整类名,使用通配符 -->
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.xiaog.service.*.*(..))" />
</aop:config> </beans>

spring-context.xml

(3)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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 1.启动自动扫描 -->
<context:component-scan base-package="com.xiaog.controller" /> <!-- 2.注册MVC注解驱动 -->
<mvc:annotation-driven /> <!-- 3.配置静态资源 css js imgs -->
<mvc:resources location="/resources/**" mapping="/resources"/>
<mvc:resources location="/webapp/static/**" mapping="/webapp/static"/> <!-- 4.附件上传 -->
<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> -->
<!-- 默认编码 -->
<!-- <property name="defaultEncoding" value="utf-8" /> -->
<!-- 文件大小最大值 -->
<!-- <property name="maxUploadSize" value="10485760000" /> -->
<!-- 内存中的最大值 -->
<!-- <property name="maxInMemorySize" value="40960" /> -->
<!-- 启用是为了推迟文件解析,以便捕获文件大小异常 -->
<!-- <property name="resolveLazily" value="true"/> -->
<!-- </bean> --> <!-- 5.配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value="/" /><!-- 前缀 -->
<property name = "suffix" value = ".jsp" /><!-- 后缀 -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean> </beans>

spring-mvc.xml

(4)logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<!-- <Encoding>UTF-8</Encoding> -->
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
<!-- 打印sql语句 -->
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />  
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />  
<logger name="org.hibernate.SQL" level="DEBUG" />
  <logger name="org.hibernate.type" level="INFO" />
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />  
  <logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
</configuration>

logback.xml

(5)jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssh?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf8
jdbc.username=root
jdbc.password=root

jdbc.properties

(6)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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>testssh</display-name>
<!-- spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-context.xml</param-value>
</context-param>
<!-- spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 字符编码过滤器 spring web自动提供一个 -->
<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> <!-- spring mvc 配置 【中央控制器/前端控制器/总控】 -->
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置Spring mvc下的配置文件的位置和名称 -->
<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>
<!-- 可以配置扩展名,*.do -->
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!-- 添加日志监听器 -->
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>classpath:logback.xml</param-value>
</context-param>
<listener>
<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
</listener> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

web.xml

6.实体类User和Phone

package com.xiaog.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table; @Entity
@Table(name="user")
public class User { @Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id; private String username; private String password; @OneToMany(targetEntity=Phone.class)
@JoinColumn(name="user_id")
private List<Phone> phones;//一个用户拥有多部手机 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;
} public List<Phone> getPhones() {
return phones;
} public void setPhones(List<Phone> phones) {
this.phones = phones;
} @Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", password=" + password + ", phones=" + phones + "]";
} }

User

package com.xiaog.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table; @Entity
@Table(name="phone")
public class Phone { @Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id; private String brand;//品牌 public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getBrand() {
return brand;
} public void setBrand(String brand) {
this.brand = brand;
} @Override
public String toString() {
return "Phone [id=" + id + ", brand=" + brand + "]";
} }

Phone

7.核心dao接口及其实现

package com.xiaog.core.dao;

import java.util.List;

public interface CoreDao<T> {

    int insert(T t);

    int delete(int id);

    int update(T t);

    T getOne(int id);

    List<T> getList(T t);

}

CoreDao

package com.xiaog.core.dao.impl;

import java.lang.reflect.ParameterizedType;
import java.util.List; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport; import com.xiaog.core.dao.CoreDao;
import com.xiaog.entity.User; //继承HibernateDaoSupport 可以直接使用CRUD操作
public class CoreDaoImpl<T> extends HibernateDaoSupport implements CoreDao<T> { private Class<T> clazz; private final static Logger logger = LoggerFactory.getLogger(CoreDaoImpl.class); @SuppressWarnings("unchecked")
public CoreDaoImpl() {
this.clazz = (Class<T>)((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
} @Override
public int insert(T t) {
return (int) super.getHibernateTemplate().save(t);
} @Override
public int delete(int id) {
super.getHibernateTemplate().delete(new User() {{setId(id);}});
return 1;
} @Override
public int update(T t) {
super.getHibernateTemplate().update(t);
return 1;
} @Override
public T getOne(int id) {
return super.getHibernateTemplate().get(clazz, id);
} @Override
public List<T> getList(T t) {
//logger.info("进入CoreDaoImpl......");
return super.getHibernateTemplate().findByExample(t);
} }

CoreDaoImpl

8.模块dao接口及其实现(只需继承核心dao即可)

package com.xiaog.dao;

import com.xiaog.core.dao.CoreDao;
import com.xiaog.entity.User; public interface UserDao extends CoreDao<User> { }

UserDao

package com.xiaog.dao;

import com.xiaog.core.dao.CoreDao;
import com.xiaog.entity.Phone; public interface PhoneDao extends CoreDao<Phone> { }

PhoneDao

package com.xiaog.dao.impl;

import org.springframework.stereotype.Repository;

import com.xiaog.core.dao.impl.CoreDaoImpl;
import com.xiaog.dao.UserDao;
import com.xiaog.entity.User; @Repository
public class UserDaoImpl extends CoreDaoImpl<User> implements UserDao { }

UserDaoImpl

package com.xiaog.dao.impl;

import org.springframework.stereotype.Repository;

import com.xiaog.core.dao.impl.CoreDaoImpl;
import com.xiaog.dao.PhoneDao;
import com.xiaog.entity.Phone; @Repository
public class PhoneDaoImpl extends CoreDaoImpl<Phone> implements PhoneDao { }

PhoneDaoImpl

9.service接口及其实现

package com.xiaog.service;

import com.xiaog.entity.User;

public interface UserService {
User login(User user);
}

UserService

package com.xiaog.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import com.xiaog.dao.UserDao;
import com.xiaog.entity.User;
import com.xiaog.service.UserService; @Service
public class UserServiceImpl implements UserService { @Autowired
private UserDao userDao; private final static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); @Override
public User login(User user) {
//logger.info("进入UserServiceImpl......");
List<User> users = userDao.getList(user);
logger.info("users="+users);
if(users!=null&&users.size()>0) {
return users.get(0);
}else {
return null;
}
} }

UserServiceImpl

10.controller

package com.xiaog.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import com.xiaog.entity.User;
import com.xiaog.service.UserService; @Controller
@RequestMapping("/user")
public class UserController { @Autowired
private UserService userService; private final static Logger logger = LoggerFactory.getLogger(UserController.class); @RequestMapping(value = "/login",params= {"username","password","username!=","password!="})
public String login(Model model,User user) {
logger.info("user(request)="+user);
user = userService.login(user);
logger.info("user="+user);
model.addAttribute("user", user);
return "result";
} }

UserController

11.jsp页面测试登录

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="user/login" method="post">
<div>
<label>username</label>
<input type="text" name="username"/>
</div>
<div>
<label>password</label>
<input type="password" name="password"/>
</div>
<div>
<input type="submit" value="登录">
</div>
</form>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
username=${user}
</body>
</html>

result.jsp

12.项目启动后,你会发现你的ssh数据库中多了两张表User和Phone,自己在插入几条数据

user表                                                 phone表

      

13.测试

index.jsp表单中输入1001和123

result.jsp

控制台打印

2019-06-22 09:40:24.477 [http-bio-9999-exec-9] INFO  com.xiaog.controller.UserController - user(request)=User [id=null, username=1002, password=456, phones=null]
2019-06-22 09:40:24.519 [http-bio-9999-exec-9] DEBUG org.hibernate.SQL - select this_.id as id1_1_0_, this_.password as password2_1_0_, this_.username as username3_1_0_ from user this_ where (this_.password=? and this_.username=?)
Hibernate: select this_.id as id1_1_0_, this_.password as password2_1_0_, this_.username as username3_1_0_ from user this_ where (this_.password=? and this_.username=?)
2019-06-22 09:40:24.520 [http-bio-9999-exec-9] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - 456
2019-06-22 09:40:24.520 [http-bio-9999-exec-9] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - 1002
2019-06-22 09:40:24.523 [http-bio-9999-exec-9] DEBUG org.hibernate.SQL - select phones0_.user_id as user3_1_1_, phones0_.id as id1_0_1_, phones0_.id as id1_0_0_, phones0_.brand as brand2_0_0_ from phone phones0_ where phones0_.user_id=?
Hibernate: select phones0_.user_id as user3_1_1_, phones0_.id as id1_0_1_, phones0_.id as id1_0_0_, phones0_.brand as brand2_0_0_ from phone phones0_ where phones0_.user_id=?
2019-06-22 09:40:24.524 [http-bio-9999-exec-9] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - 2
2019-06-22 09:40:24.533 [http-bio-9999-exec-9] INFO com.xiaog.service.impl.UserServiceImpl - users=[User [id=2, username=1002, password=456, phones=[Phone [id=3, brand=三星], Phone [id=4, brand=小米], Phone [id=5, brand=魅族]]]]
2019-06-22 09:40:24.557 [http-bio-9999-exec-9] INFO com.xiaog.controller.UserController - user=User [id=2, username=1002, password=456, phones=[Phone [id=3, brand=三星], Phone [id=4, brand=小米], Phone [id=5, brand=魅族]]]
2019-06-22 10:38:09.540 [http-bio-9999-exec-5] INFO com.xiaog.controller.UserController - user(request)=User [id=null, username=1001, password=123, phones=null]
2019-06-22 10:38:09.549 [http-bio-9999-exec-5] DEBUG org.hibernate.SQL - select this_.id as id1_1_0_, this_.password as password2_1_0_, this_.username as username3_1_0_ from user this_ where (this_.password=? and this_.username=?)
Hibernate: select this_.id as id1_1_0_, this_.password as password2_1_0_, this_.username as username3_1_0_ from user this_ where (this_.password=? and this_.username=?)
2019-06-22 10:38:09.550 [http-bio-9999-exec-5] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - 123
2019-06-22 10:38:09.550 [http-bio-9999-exec-5] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - 1001
2019-06-22 10:38:09.554 [http-bio-9999-exec-5] DEBUG org.hibernate.SQL - select phones0_.user_id as user3_1_1_, phones0_.id as id1_0_1_, phones0_.id as id1_0_0_, phones0_.brand as brand2_0_0_ from phone phones0_ where phones0_.user_id=?
Hibernate: select phones0_.user_id as user3_1_1_, phones0_.id as id1_0_1_, phones0_.id as id1_0_0_, phones0_.brand as brand2_0_0_ from phone phones0_ where phones0_.user_id=?
2019-06-22 10:38:09.556 [http-bio-9999-exec-5] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - 1
2019-06-22 10:38:09.563 [http-bio-9999-exec-5] INFO com.xiaog.service.impl.UserServiceImpl - users=[User [id=1, username=1001, password=123, phones=[Phone [id=1, brand=华为], Phone [id=2, brand=iphone]]]]
2019-06-22 10:38:09.570 [http-bio-9999-exec-5] INFO com.xiaog.controller.UserController - user=User [id=1, username=1001, password=123, phones=[Phone [id=1, brand=华为], Phone [id=2, brand=iphone]]]

14.注意点:我个人觉得ssh框架坑实在是多,我在搭建的过程中出现了各种各样的问题,不过最恶心的问题是spring和hibernate存在版本不兼容问题,一开始使用的是spring5+hibernate5,发现报错,就将hibernate5换成4(应该没问题了吧),结果还是报错,折腾半天,发现虽然Pom版本虽然换成4,但是之前dao层用到的HibernateDaoSupport和spring-context.xml配置中SessionFactory还是5的版本,诶,智障问题。

javaweb各种框架组合案例(三):maven+spring+springMVC+hibernate的更多相关文章

  1. javaweb各种框架组合案例(四):maven+spring+springMVC+spring data jpa(hibernate)【失败案例】

    一.失败案例 1. 控制台报错信息 严重: Exception sending context initialized event to listener instance of class org. ...

  2. javaweb各种框架组合案例(二):maven+spring+springMVC+mybatis

    1.mybatis是比较新的半自动orm框架,效率也比较高,优点是sql语句的定制,管理与维护,包括优化,缺点是对开发人员的sql功底要求较高,如果比较复杂的查询,表与表之间的关系映射到对象与对象之间 ...

  3. javaweb各种框架组合案例(六):springboot+spring data jpa(hibernate)+restful

    一.介绍 1.springboot是spring项目的总结+整合 当我们搭smm,ssh,ssjdbc等组合框架时,各种配置不胜其烦,不仅是配置问题,在添加各种依赖时也是让人头疼,关键有些jar包之间 ...

  4. javaweb各种框架组合案例(一):maven+spring+springMVC+jdbcTemplate

    为了体现spring jdbc对于单表操作的优势,我专门对dao层做了一个抽离,使得抽离出的核心dao具有通用性.主要技术难点是对于泛型的反射.注意:单表操作中,数据库表的字段要和实体类的属性名保持高 ...

  5. javaweb各种框架组合案例(五):springboot+mybatis+generator

    一.介绍 1.springboot是spring项目的总结+整合 当我们搭smm,ssh,ssjdbc等组合框架时,各种配置不胜其烦,不仅是配置问题,在添加各种依赖时也是让人头疼,关键有些jar包之间 ...

  6. javaweb各种框架组合案例(八):springboot+mybatis-plus+restful

    一.介绍 1. springboot是spring项目的总结+整合 当我们搭smm,ssh,ssjdbc等组合框架时,各种配置不胜其烦,不仅是配置问题,在添加各种依赖时也是让人头疼,关键有些jar包之 ...

  7. javaweb各种框架组合案例(七):springboot+jdbcTemplete+通用dao+restful

    一.介绍 1.springboot是spring项目的总结+整合 当我们搭smm,ssh,ssjdbc等组合框架时,各种配置不胜其烦,不仅是配置问题,在添加各种依赖时也是让人头疼,关键有些jar包之间 ...

  8. javaweb各种框架组合案例(九):springboot+tk.mybatis+通用service

    一.项目结构 二.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...

  9. maven+Spring+SpringMVC+Hibernate快速搭建

    目录结构: pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&qu ...

随机推荐

  1. Vue.JS学习基础

      = 导航   顶部 vue.js介绍 vue.js实例 模板语法 计算属性 样式绑定 条件渲染 列表渲染 事件处理器 表单控件绑定 组件   顶部 vue.js介绍 vue.js实例 模板语法 计 ...

  2. gdal库集成MrSID库的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 首先从Lizardtech网站:http://www.lizardtech.com/download/develope ...

  3. wpf控件设计时支持(1)

    原文:wpf控件设计时支持(1) 这部分内容几乎是大家忽略的内容,我想还是来介绍一下. 本篇源码下载 1.属性元数据 在vs IDE中,在asp.net,winfrom等开发环境下,右侧的Proper ...

  4. 大约laravel错误的解决方案

    2015-3-13 夜晚 9:13 执行laravel发生错误Indirect modification of overloaded element of BbsArticle has no effe ...

  5. VCL to UniGUI Migration Wizard

    Free Evaluation Edition of The Automatic Migration Scripting Wizard For Converting Legacy Delphi Cod ...

  6. [Gevent]gevent 网络抓取问答

    我听说过gevent基于事件的异步处理功能 如何高效率,该项目已很少使用,今天是没什么学习一些简单的使用. 有正式书面一个非常好的教程 中国版的地址:http://xlambda.com/gevent ...

  7. 潜移默化学会WPF(绚丽篇)--热烈欢迎RadioButton,改造成功,改造成ImageButton,新版导航

    原文:潜移默化学会WPF(绚丽篇)--热烈欢迎RadioButton,改造成功,改造成ImageButton,新版导航 本样式 含有  触发器 和 动画    模板  ,多条件触发器,还有布局 本人博 ...

  8. EF延迟加载LazyLoading

    优点 只在需要的时候加载数据,不需要预先计划,避免了各种复杂的外连接.索引.视图操作带来的低效率问题 缺陷:多次与DB交互,性能降低 阻止延迟加载解决方案:1.ToList(),返回的东西是个内存级的 ...

  9. 通通WPF随笔(4)——通通手写输入法(基于Tablet pc实现)

    原文:通通WPF随笔(4)--通通手写输入法(基于Tablet pc实现) 从我在博客园写第一篇博客到现在已经有1年半了,我的第一篇博客写的就是手写识别,当时,客户需求在应用中加入手写输入功能,由于第 ...

  10. wpf 复制/剪切到本地系统剪切板中以供右键粘贴用

    原文:wpf 复制/剪切到本地系统剪切板中以供右键粘贴用   http://www.cnblogs.com/yhdkzy/archive/2012/11/27/2790655.html   /// & ...