国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Spring+SpringMVC+Hibernate整合實例講解

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

使用Maven構建項目,用pom.xml引入相應jar,配置以下文件

創建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>

創建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>

創建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> <!-- 設置方言 --> <property name='dialect'>org.hibernate.dialect.MySQL5InnoDBDialect</property> <!-- 配置生成SQL的打印 --> <property name='hibernate.show_sql'>true</property> <property name='hibernate.format_sql'>true</property> <!-- 設置自動生成表 --> <property name='hibernate.hbm2ddl.auto'>update</property> <property name='hibernate.connection.isolation'>4</property> </session-factory></hibernate-configuration>

創建db.properties

jdbc.driver=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/數據庫名jdbc.username='' #這里自己填寫 jdbc.password='' #這里自己填寫

整合SSH的配置文件已經完成

到此這篇關于Spring+SpringMVC+Hibernate整合實例講解的文章就介紹到這了,更多相關Spring+SpringMVC+Hibernate整合內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 欧美成人xxxx | 国产黄色免费网站 | 波多结衣一区二区三区 | 久久草在线视频 | a毛片在线 | 久久久久久尹人网香蕉 | 狠狠色综合网站久久久久久久 | 亚洲一级特黄特黄的大片 | 亚洲一区二区三区国产精品 | 国产久草视频在线 | 国产精品久久久久久久9999 | 国产毛片基地 | 成人a大片高清在线观看 | 黄网站色成年小说系列 | 午夜不卡在线 | 精品国产一区二区三区国产馆 | 手机看片亚洲 | 中国欧美一级毛片免费 | 91探花福利精品国产自产在线 | 亚洲天堂免费看 | 日韩美一区二区 | 精品性久久 | 久久精品免费一区二区视 | 1717she国产精品免费视频 | 在线日本看片免费人成视久网 | 91精品乱码一区二区三区 | 久久久久在线观看 | 日本欧美一区二区 | 精品国产一二三区在线影院 | 亚洲一区二区三区久久精品 | 国产理论视频在线观看 | 5x性区m免费毛片视频看看 | 成人性免费视频 | 欧美成a| 国产欧美亚洲精品 | 99re国产视频| 色精品一区二区三区 | 一级黄色香蕉视频 | 亚洲 欧美 精品 | 久久久亚洲国产精品主播 | 青青草福利视频 |