spring整合hibernate的方法是什么-創(chuàng)新互聯(lián)

本篇文章給大家分享的是有關(guān)spring整合hibernate的方法是什么,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

在東區(qū)等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供做網(wǎng)站、成都做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站建設(shè),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),東區(qū)網(wǎng)站建設(shè)費(fèi)用合理。

結(jié)構(gòu):

Spring和Hibernate整合借助于HibernateTemplate

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="/tupian/20230522/"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:aop="/tupian/20230522/"  xmlns:tx="/tupian/20230522/"  xmlns:context="/tupian/20230522/"  xsi:schemaLocation="  /tupian/20230522/   /tupian/20230522//spring-beans-3.0.xsd  /tupian/20230522/   /tupian/20230522//spring-aop-3.0.xsd  /tupian/20230522/   /tupian/20230522//spring-tx-3.0.xsd  /tupian/20230522/     /tupian/20230522//spring-context-3.0.xsd">   <bean name="c" class="com.lc.pojo.Category">    <property name="name" value="yyy" />  </bean>    <bean name="dao" class="com.lc.dao.CategoryDAO">    <property name="sessionFactory" ref="sf" />  </bean>  <bean name="sf"    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    <property name="dataSource" ref="ds" />    <property name="mappingResources">      <list>        <value>com/lc/pojo/Category.hbm.xml</value>      </list>    </property>    <property name="hibernateProperties">      <value>        hibernate.dialect=org.hibernate.dialect.MySQLDialect        hibernate.show_sql=true        hbm2ddl.auto=update        </value>    </property>  </bean>      <!--  數(shù)據(jù)源-->  <bean name="ds"    class="org.springframework.jdbc.datasource.DriverManagerDataSource">    <property name="driverClassName" value="com.mysql.jdbc.Driver" />    <property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=GBK" />    <property name="username" value="root" />    <property name="password" value="123456" />  </bean>   </beans>

測試:

ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");    CategoryDAO bean =(CategoryDAO) context.getBean("dao");    DetachedCriteria criteria = DetachedCriteria.forClass(Category.class);//    List<Category> list = bean.findByCriteria(criteria, 0, 5); //分頁--取0-5個(gè)返回//    System.out.println(list);

Category.hbm.xml

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.lc.pojo">  <class name="Category" table="category_">    <id name="id" column="id">      <generator class="native">      </generator>    </id>    <property name="name" />  </class></hibernate-mapping>


以上就是spring整合hibernate的方法是什么,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

名稱欄目:spring整合hibernate的方法是什么-創(chuàng)新互聯(lián)
本文地址:http://www.muchs.cn/article22/dhoejc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站小程序開發(fā)、手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、全網(wǎng)營銷推廣做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)