欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解spring整合hibernate的方法

 更新時(shí)間:2020年02月03日 08:58:47   作者:crazy戴夫  
這篇文章主要介紹了spring整合hibernate的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

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

Spring和Hibernate整合借助于HibernateTemplate

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  http://www.springframework.org/schema/tx 
  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  http://www.springframework.org/schema/context   
  http://www.springframework.org/schema/context/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>

測(cè)試:

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); //分頁(yè)--取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>

result:

總結(jié)

以上所述是小編給大家介紹的spring整合hibernate的方法,希望對(duì)大家有所幫助!

相關(guān)文章

  • 快速掌握J(rèn)ava中注解與反射

    快速掌握J(rèn)ava中注解與反射

    本文詳細(xì)介紹了Java中注解和反射的概念及應(yīng)用,注解是用于給代碼添加元數(shù)據(jù)的標(biāo)記,如@Override、@Deprecated等,反射機(jī)制則是在運(yùn)行時(shí)獲取和操作類(lèi)的內(nèi)部信息,提高了代碼的靈活度,感興趣的朋友跟隨小編一起看看吧
    2023-06-06
  • 基于selenium-java封裝chrome、firefox、phantomjs實(shí)現(xiàn)爬蟲(chóng)

    基于selenium-java封裝chrome、firefox、phantomjs實(shí)現(xiàn)爬蟲(chóng)

    這篇文章主要介紹了基于selenium-java封裝chrome、firefox、phantomjs實(shí)現(xiàn)爬蟲(chóng),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • servlet實(shí)現(xiàn)文件下載的步驟及說(shuō)明詳解

    servlet實(shí)現(xiàn)文件下載的步驟及說(shuō)明詳解

    這篇文章主要為大家詳細(xì)介紹了servlet實(shí)現(xiàn)文件下載的步驟及說(shuō)明,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • MyBatis-Plus如何通過(guò)注解使用TypeHandler

    MyBatis-Plus如何通過(guò)注解使用TypeHandler

    這篇文章主要介紹了MyBatis-Plus如何通過(guò)注解使用TypeHandler,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • springboot項(xiàng)目啟動(dòng)類(lèi)錯(cuò)誤(找不到或無(wú)法加載主類(lèi) com.**Application)

    springboot項(xiàng)目啟動(dòng)類(lèi)錯(cuò)誤(找不到或無(wú)法加載主類(lèi) com.**Application)

    本文主要介紹了spring-boot項(xiàng)目啟動(dòng)類(lèi)錯(cuò)誤(找不到或無(wú)法加載主類(lèi) com.**Application),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-05-05
  • IDEA中的.iml文件和.idea文件夾使用方式

    IDEA中的.iml文件和.idea文件夾使用方式

    這篇文章主要介紹了IDEA中的.iml文件和.idea文件夾使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Java集合之同步容器詳解

    Java集合之同步容器詳解

    這篇文章主要為大家詳細(xì)介紹了Java集合之同步容器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Java Mybatis批量修改封裝詳解

    Java Mybatis批量修改封裝詳解

    這篇文章主要介紹了Mybatis批量修改封裝的相關(guān)內(nèi)容,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • Java中判斷對(duì)象是否為空的方法的詳解

    Java中判斷對(duì)象是否為空的方法的詳解

    這篇文章主要介紹了Java中判斷對(duì)象是否為空的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • java定長(zhǎng)隊(duì)列的實(shí)現(xiàn)示例

    java定長(zhǎng)隊(duì)列的實(shí)現(xiàn)示例

    定長(zhǎng)隊(duì)列是一種有限容量的隊(duì)列,對(duì)于某些應(yīng)用場(chǎng)景非常有用,本文主要介紹了java定長(zhǎng)隊(duì)列的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02

最新評(píng)論