2019独角兽企业重金招聘Python工程师标准>>>

package com.lei.demo.entity;
import javax.persistence.*;
@Entity(name="users")
public class Users {public Users(){super();}@Id@GeneratedValue(strategy=GenerationType.AUTO)@Column(name="id")private Integer id;@Column(name="user_name",length=32)private String user_name;@Column(name="age")private Integer age;@Column(name="nice_name",length=32)private String nice_name;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUser_name() {return user_name;}public void setUser_name(String user_name) {this.user_name = user_name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public String getNice_name() {return nice_name;}public void setNice_name(String nice_name) {this.nice_name = nice_name;}
}
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>Archetype Created Web Application</display-name><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:/spring-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 定义DispatcherServlet --><servlet><servlet-name>lei-dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><!-- 默认/WEB-INF/[servlet名字]-servlet.xml加载上下文, 如果配置了contextConfigLocation参数,将使用classpath:/lei-dispatcher-servlet.xml加载上下文--><param-name>contextConfigLocation</param-name><param-value>classpath:/lei-dispatcher-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- 拦截匹配的请求,这里所有请求采用名字为lei-dispatcher的DispatcherServlet处理 --><servlet-mapping><servlet-name>lei-dispatcher</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd"><!-- 启动自动扫描该包下所有的Bean(例如@Controller) --><context:component-scan base-package="com.lei.demo" /><!-- 定义视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix"><value>/WEB-INF/user/</value></property><property name="suffix"><value>.jsp</value></property></bean></beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd"><!-- Hibernate4 --><!-- 加载资源文件  其中包含变量信息,必须在Spring配置文件的最前面加载,即第一个加载--><context:property-placeholder location="classpath:persistence-mysql.properties" /><bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="packagesToScan"><list><!-- 可以加多个包 --><value>com.lei.demo.entity</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop><prop key="hibernate.dialect">${hibernate.dialect}</prop><prop key="hibernate.show_sql">${hibernate.show_sql}</prop><!--  <prop key="hibernate.current_session_context_class">thread</prop> --> </props></property></bean><!-- 数据库映射 --><!--  class="org.apache.tomcat.dbcp.dbcp.BasicDataSource" --><!--  class="org.springframework.jdbc.datasource.DriverManagerDataSource" --><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.user}" /><property name="password" value="${jdbc.pass}" /></bean><!-- 配置Hibernate事务管理器 --><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- 配置事务异常封装 --><bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /><!--  声明式容器事务管理 ,transaction-manager指定事务管理器为transactionManager --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="add*" propagation="REQUIRED" /><tx:method name="get*" propagation="REQUIRED" /><tx:method name="*" read-only="true" /></tx:attributes></tx:advice><aop:config expose-proxy="true"><!-- 只对业务逻辑层实施事务 --><aop:pointcut id="txPointcut" expression="execution(* com.lei.demo.service..*.*(..))" /><!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice --><aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice"/></aop:config></beans>
# jdbc.X
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://yourServerIP:3306/yourDatabase?createDatabaseIfNotExist=true
jdbc.user=user
jdbc.pass=password
# hibernate.X
hibernate.connection.driverClass=org.gjt.mm.mysql.Driver
hibernate.connection.url=jdbc:mysql:// yourServerIP:3306/yourDatabase
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.connection.username=user
hibernate.connection.password=password
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create-drop

详情

http://www.cnblogs.com/leiOOlei/p/3727859.html

转载于:https://my.oschina.net/u/2291124/blog/386821

Spring4 MVC Hibernate4集成相关推荐

  1. 基于全注解的SpringMVC+Spring4.2+hibernate4.3框架搭建

    概述 从0到1教你搭建spring+springMVC+hibernate整合框架,基于注解. 本教程框架为基于全注解的SpringMVC+Spring4.2+hibernate4.3,开发工具为my ...

  2. Spring4整合Hibernate4出现的错误的解决

    今天在使用Spring4整合Hibernate4过程中出现错误 org.hibernate.HibernateException: Could not obtain transaction-synch ...

  3. Spring4 MVC + REST + List + Bootstrap 简单示例

    本篇文章,我们将教会你通过eclipse创建并转换为maven的web项目.通过spring4 mvc提供的REST方式将List对象中的值通JSTL 的c:forEach 标签输出到页面中(本篇文章 ...

  4. 如何在 ASP.NET MVC 中集成 AngularJS(3)

    今天来为大家介绍如何在 ASP.NET MVC 中集成 AngularJS 的最后一部分内容. 调试路由表 - HTML 缓存清除 就在我以为示例应用程序完成之后,我意识到,我必须提供两个版本的路由表 ...

  5. 如何在 ASP.NET MVC 中集成 AngularJS(2)

    在如何在 ASP.NET MVC 中集成 AngularJS(1)中,我们介绍了 ASP.NET MVC 捆绑和压缩.应用程序版本自动刷新和工程构建等内容. 下面介绍如何在 ASP.NET MVC 中 ...

  6. 如何在 ASP.NET MVC 中集成 AngularJS

    介绍 当涉及到计算机软件的开发时,我想运用所有的最新技术.例如,前端使用最新的 JavaScript 技术,服务器端使用最新的基于 REST 的 Web API 服务.另外,还有最新的数据库技术.最新 ...

  7. knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案

    knife4j knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,前身是swagger-bootstrap-ui,取名kni4j是希望它能像一把匕首一样小巧,轻量, ...

  8. java json 返回null,[] Spring4 MVC 返回json格式时候 设置不返回null值属性的有关问题...

    [求助] Spring4 MVC 返回json格式时候 设置不返回null值属性的问题 本帖最后由 bighong0404 于 2015-10-06 12:45:38 编辑 背景: 使用@respon ...

  9. Spring4 MVC HelloWorld 注解和JavaConfig实例

    在这一节中,我们以 Spring4 MVC HelloWorld 注释/JavaConfig为示例,一步一步以简单的方式学习Spring4 MVC 的注解,项目设置,代码,部署和运行. 在先前的 Sp ...

最新文章

  1. Ubuntu 忘记root登录密码的解决办法
  2. 在spring web中启动mqtt
  3. webpack 中的加载器简介||webpack 中加载器的基本使用——1. 打包处理 css 文件 2. 打包处理 less 文件 3.打包处理 scss 文件
  4. python3.7扩展库是什么_Python3.4以后的版本中,____________库用于安装管理Python扩展包,________________库用于发布Python包。_学小易找答案...
  5. ios 监听一个控制器的属性_OC观察者模式之KVO的使用与思考
  6. support mobile touch event
  7. 数据库入门开发案例,真的是入门级别的!!看了不后悔。
  8. matlab13节点线路模型,13节点配电网的建模与仿真.doc
  9. Java高级工程师必看系列,从基础到源码统统帮你搞定
  10. mysql数控不小心被删_mysql 数据库信息不小心被删除了, 请问能恢复么
  11. zynq开发系列4:MIO按键中断控制LED
  12. docker安装vim命令
  13. 基于Windows AD的单点登录系统
  14. 软件设计师考试都考什么内容
  15. 【金三银四】TCP,UDP,Socket,Http网络编程面试题(2021最新版)
  16. Oracle标准成本差异,标准成本与实际成本比较
  17. 芝麻信用商家接入指南
  18. 计算机科任学 排名,2018软科中国最好学科排名正式发布
  19. win32 应用程序更换icon图标
  20. overshoot是什么matlab,Overshoot metrics of bilevel waveform transitions

热门文章

  1. RabbitMQ的消费限流
  2. kalinux实现自适用全屏、与物理主机共享文件方法
  3. python网络编程及高并发问题
  4. jsPlumb.jsAPI阅读笔记(官方文档翻译)
  5. Java多线程1:进程与线程概述
  6. github 笔记
  7. 解决sybase数据库的死锁问题
  8. 使用crypto模块实现md5加密功能(解决中文加密前后端不一致的问题)
  9. 记录一次异常 出现不支持的 SQL92 标记: 70
  10. ssh 远程登陆异常SSH_EXCHANGE_IDENTIFICATION及解决过程