午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:160日期:2023-09-17 08:21:13

使用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 transaction-manager='hibernateTransactionManager'></tx:advice> <aop:config> <aop:pointcut expression='execution(* com.forum.service.*.*(..))' /> <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.Driverjdbc.url=jdbc:mysql://localhost:3306/數(shù)據(jù)庫名jdbc.username='' #這里自己填寫 jdbc.password='' #這里自己填寫

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

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 色虎在线观看 | 日韩男女视频 | 国产成人精品网站 | 久久精品偷拍视频 | 日本在线观看网址 | 在线激情av| www视频在线免费观看 | 天天av网 | 日韩一区二区三区免费视频 | 99视频一区二区 | 久久国产精品波多野结衣av | 久久国产精品久久精品国产 | 日韩免费不卡视频 | 日本黄色免费看 | 成人免费在线观看 | 91精品久久久久久久久 | 国产精品久久久久久久久久久久 | 国产乱码精品1区2区3区 | 国产免费成人 | 91精品国产一区二区 | av色图 | 日韩免费视频一区二区 | 国产深夜福利 | 91视频日本 | av一二三四 | 亚洲二区视频 | 大伊香蕉 | 久久亚洲在线 | 成人小视频免费在线观看 | 114国产精品久久免费观看 | 婷五月天 | 伊人网在线视频观看 | 一级黄色片在线播放 | 日本三级精品 | 黄色的视频网站 | 中文字幕视频在线观看 | 神马一区二区三区 | 欧美刺激脚交jootjob | 国产精品情侣 | 久久久久久久久久久网站 | 久草福利在线视频 |