最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring+SpringMVC+Hibernate整合實(shí)例講解

 更新時(shí)間:2020年03月10日 14:46:32   作者:LeoRiver  
在本篇文章里小編給大家整理的是關(guān)于Spring+SpringMVC+Hibernate整合實(shí)例講解,需要的朋友們可以學(xué)習(xí)下。

使用Maven構(gòu)建項(xiàng)目,用pom.xml引入相應(yīng)jar,配置以下文件

創(chuàng)建spring.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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"
  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.3.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
  <!-- 整合Hibernate -->
  <context:property-placeholder location="classpath:db.properties"/>
  
  <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driver}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
  </bean>
  
  <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    <property name="mappingLocations" value="classpath:mapping/*.hbm.xml"></property>
  </bean>
  
  <bean name="hibernateTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
  
  <tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager"></tx:advice>  
  
  <aop:config>
    <aop:pointcut expression="execution(* com.forum.service.*.*(..))" id="pointCut"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut"/>
  </aop:config>
  
  <context:component-scan base-package="com.forum">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  </context:component-scan>
</beans>

創(chuàng)建springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
    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.3.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
  <!-- 配置MessageConvertor -->
  <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
      <list>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
          <property name="supportedMediaTypes">
            <list>
              <value>application/json;charset=utf-8</value>
            </list>
          </property>
        </bean>
      </list>
    </property>
  </bean>
  
  <!-- 配置模板引擎 -->
  <bean name="templateResolver" class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".html"/>
    <property name="templateMode" value="HTML"/>
    <property name="cacheable" value="false"/>
    <property name="characterEncoding" value="UTF-8"/>
  </bean>
  
  <bean name="templateEngine" class="org.thymeleaf.spring5.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver"/>
  </bean>
  
  <bean class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine"/>
    <property name="characterEncoding" value="utf-8"/>
  </bean>
  
  <mvc:annotation-driven></mvc:annotation-driven>
  
  <mvc:default-servlet-handler/>
  
  <context:component-scan base-package="com.forum">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  </context:component-scan>
</beans>

創(chuàng)建hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <!-- 設(shè)置方言 -->
    <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <!-- 配置生成SQL的打印 -->
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <!-- 設(shè)置自動(dòng)生成表 -->
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.connection.isolation">4</property>
  </session-factory>
</hibernate-configuration>

創(chuàng)建db.properties

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/數(shù)據(jù)庫(kù)名
jdbc.username="" #這里自己填寫(xiě)
jdbc.password="" #這里自己填寫(xiě)

整合SSH的配置文件已經(jīng)完成

到此這篇關(guān)于Spring+SpringMVC+Hibernate整合實(shí)例講解的文章就介紹到這了,更多相關(guān)Spring+SpringMVC+Hibernate整合內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺談一下maven優(yōu)缺點(diǎn)及使用和特點(diǎn)

    淺談一下maven優(yōu)缺點(diǎn)及使用和特點(diǎn)

    這篇文章主要介紹了淺談一下maven優(yōu)缺點(diǎn)及使用和特點(diǎn),一個(gè)項(xiàng)目管理工具軟件,那么maven項(xiàng)目有什么優(yōu)缺點(diǎn)呢,讓我們一起來(lái)看看吧
    2023-03-03
  • 如何用nacos搭建微服務(wù)注冊(cè)配置中心

    如何用nacos搭建微服務(wù)注冊(cè)配置中心

    這篇文章主要介紹了如何用nacos搭建微服務(wù)注冊(cè)配置中心問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 深入理解Java虛擬機(jī) JVM 內(nèi)存結(jié)構(gòu)

    深入理解Java虛擬機(jī) JVM 內(nèi)存結(jié)構(gòu)

    本節(jié)將會(huì)介紹一下JVM的內(nèi)存結(jié)構(gòu),JVM運(yùn)行時(shí)數(shù)據(jù)區(qū)的各個(gè)組成部分:堆,方法區(qū),程序計(jì)數(shù)器,Java虛擬機(jī)棧,本地方法棧,還會(huì)對(duì)Java堆的分代劃分做個(gè)簡(jiǎn)單的介紹
    2021-09-09
  • 我賭你不清楚Spring中關(guān)于Null的這些事

    我賭你不清楚Spring中關(guān)于Null的這些事

    這篇文章主要介紹了我賭你不清楚Spring中關(guān)于Null的這些事,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • MyBatis開(kāi)發(fā)Dao層的兩種方式實(shí)現(xiàn)(原始Dao層開(kāi)發(fā))

    MyBatis開(kāi)發(fā)Dao層的兩種方式實(shí)現(xiàn)(原始Dao層開(kāi)發(fā))

    這篇文章主要介紹了MyBatis開(kāi)發(fā)Dao層的兩種方式實(shí)現(xiàn)(原始Dao層開(kāi)發(fā)),并對(duì)數(shù)據(jù)庫(kù)進(jìn)行增刪查改,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • Java由淺入深通關(guān)抽象類(lèi)與接口上

    Java由淺入深通關(guān)抽象類(lèi)與接口上

    在類(lèi)中沒(méi)有包含足夠的信息來(lái)描繪一個(gè)具體的對(duì)象,這樣的類(lèi)稱(chēng)為抽象類(lèi),接口是Java中最重要的概念之一,它可以被理解為一種特殊的類(lèi),不同的是接口的成員沒(méi)有執(zhí)行體,是由全局常量和公共的抽象方法所組成,本文給大家介紹Java抽象類(lèi)和接口,感興趣的朋友一起看看吧
    2022-04-04
  • 詳解Java 類(lèi)的加載機(jī)制

    詳解Java 類(lèi)的加載機(jī)制

    這篇文章主要介紹了Java 類(lèi)的加載機(jī)制,幫助大家更好的理解和學(xué)習(xí)Java,感興趣的朋友可以了解下
    2020-08-08
  • Java多線程Thread類(lèi)的使用及注意事項(xiàng)

    Java多線程Thread類(lèi)的使用及注意事項(xiàng)

    這篇文章主要介紹了Java多線程Thread類(lèi)的使用及注意事項(xiàng),在java標(biāo)準(zhǔn)庫(kù)中提供了一個(gè)Thread類(lèi)來(lái)表示/操作線程,Thread類(lèi)也可以視為是java標(biāo)準(zhǔn)庫(kù)提供的API
    2022-06-06
  • SpringBoot @ModelAttribute使用場(chǎng)景分析

    SpringBoot @ModelAttribute使用場(chǎng)景分析

    這篇文章主要介紹了SpringBoot @ModelAttribute使用場(chǎng)景分析,文中通過(guò)實(shí)例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-08-08
  • 使用Okhttp實(shí)現(xiàn)上傳文件+參數(shù)請(qǐng)求接口form-data

    使用Okhttp實(shí)現(xiàn)上傳文件+參數(shù)請(qǐng)求接口form-data

    在進(jìn)行接口對(duì)接時(shí),常遇到需要傳遞多種類(lèi)型參數(shù)及文件上傳的情況,解決此問(wèn)題的關(guān)鍵在于參數(shù)傳遞和文件上傳的正確處理,在Service層和Controller層的傳參,可以通過(guò)@RequestParam標(biāo)注或直接使用請(qǐng)求實(shí)體類(lèi),但若結(jié)合文件上傳,則不應(yīng)使用@RequestBody注解
    2024-10-10

最新評(píng)論

昌宁县| 平乡县| 邵武市| 永登县| 桑日县| 渑池县| 北海市| 南川市| 明溪县| 遵义县| 柏乡县| 织金县| 巩义市| 鄂温| 塔城市| 汝城县| 汕头市| 桃江县| 九江县| 南丰县| 新密市| 萨迦县| 子洲县| 土默特左旗| 禹州市| 海晏县| 石屏县| 永和县| 肇源县| 抚远县| 临清市| 汨罗市| 丹寨县| 孟津县| 惠安县| 台前县| 蛟河市| 如东县| 南澳县| 宁明县| 绥江县|