介绍
这期内容当中小编将会给大家带来有关如何在春天中使用hibernate,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
结构:
spring和hibernate整合借助于HibernateTemplate
applicationContext。xml
& lt; ? xml version=?.0“,编码=癠TF-8" ?比; http://www.springframework.org/schema/beans" & lt; beans  xmlns=?; ,,xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" xmlns:才能aop=癶ttp://www.springframework.org/schema/aop" xmlns:才能tx=癶ttp://www.springframework.org/schema/tx" xmlns:才能上下文=癶ttp://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"才能的在 , & lt;才能bean name=癱",类=癱om.lc.pojo.Category"比; ,,,& lt; property name=皀ame",价值=https://www.yisu.com/zixun/"多"/> 豆><属性名=" sessionFactory“ref="科幻小说"/> 豆> <属性名=笆菰础眗ef=" ds "/> <属性名=" mappingResources "> <列表> <价值>com/lc/pojo/Category.hbm.xml 值> >列表> 属性 <属性名=" hibernateProperties "> <值> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hbm2ddl.auto=更新 值> 属性 豆> <属性name=value=癲riverClassName com.mysql.jdbc。司机"/> <属性名=" url " value=" jdbc: mysql://localhost: 3306/测试?characterEncoding=GBK "/> <属性名="用户名" value="根"/> <属性名="密码" value=" 123456 "/> 豆> 豆>
测试:
ApplicationContext 上下文=new ClassPathXmlApplicationContext (“applicationContext.xml"); ,,,CategoryDAO bean =(CategoryDAO), context.getBean (“dao"); ,,,DetachedCriteria criteria =, DetachedCriteria.forClass (Category.class);//,,,,List, list =, bean.findByCriteria(0标准,,,,,,//分页——取0 - 5个返回//,,,,System.out.println(列表);
, Category.hbm。xml
& lt; ? xml version=?.0“?比; & lt; ! DOCTYPE hibernate-mapping 公众 ,,,,,//Hibernate/Hibernate Mapping DTD 3.0//EN" ,,,“http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"比; & lt; hibernate-mapping 包=癱om.lc.pojo"祝辞 & lt;才能class name=癈ategory",表=癱ategory_"比; ,,,& lt; id name=癷d",列=癷d"比; ,,,,,& lt; generator 类=皀ative"比; ,,,,,& lt;/generator> ,,,& lt;/id> ,,,& lt; property name=皀ame",/比; & lt;才能/class> & lt;/hibernate-mapping>
结果:
上述就是小编为大家分享的如何在春天中使用冬眠了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。