当前位置: 首页 > news >正文

网站怎么做分站网站电脑版和手机版区别

网站怎么做分站,网站电脑版和手机版区别,网站上图片可以做商业作品吗,奉贤做网站价格所以我想做一系列的冬眠例子#xff0c;展示冬眠的各种特征。 在第一部分中#xff0c;我想展示有关删除孤儿功能及其在故事情节中的使用方法。 因此#xff0c;让我们开始:) 先决条件 #xff1a; 为了尝试以下示例#xff0c;您将需要以下提到的JAR文件#xff1a; … 所以我想做一系列的冬眠例子展示冬眠的各种特征。 在第一部分中我想展示有关删除孤儿功能及其在故事情节中的使用方法。 因此让我们开始:) 先决条件 为了尝试以下示例您将需要以下提到的JAR文件 org.springframework.aop-3.0.6.RELEASE.jar org.springframework.asm-3.0.6.RELEASE.jar org.springframework.aspects-3.0.6.RELEASE.jar org.springframework.beans-3.0.6.RELEASE.jar org.springframework.context.support-3.0.6.RELEASE.jar org.springframework.context-3.0.6.RELEASE.jar org.springframework.core-3.0.6.RELEASE.jar org.springframework.jdbc-3.0.6.RELEASE.jar org.springframework.orm-3.0.6.RELEASE.jar org.springframework.transaction-3.0.6.RELEASE.jar。 org.springframework.expression-3.0.6.RELEASE.jar commons-logging-1.0.4.jar log4j.jar aopalliance-1.0.jar dom4j-1.1.jar hibernate-commons-annotations-3.2.0.Final.jar hibernate-core-3.6.4.Final.jar hibernate-jpa-2.0-api-1.0.0.Final.jar javax.persistence-2.0.0.jar jta-1.1.jar javassist-3.1.jar slf4j-api-1.6.2.jar mysql-connector-java-5.1.13-bin.jar commons-collections-3.0.jar 对于希望eclipse项目进行尝试的任何人您都可以在此处下载带有上述JAR依赖项的文件。 简介 成立于2011年。正义联盟Justice League的规模过大正在寻找开发商来帮助创建超级英雄注册系统。 熟悉Hibernate和ORM的开发人员已准备好使用Hibernate来完成系统和处理持久层的工作。 为简单起见他将使用一个简单的独立应用程序来保留超级英雄。 这是此示例的布局方式 桌子设计 域类和Hibernate映射 DAO和服务类 应用程序的Spring配置 一个简单的主类展示所有工作原理 让旅程开始……………………。 表格设计 设计由三个简单的表格组成如下图所示 如您所见它是一个简单的一对多关系由联接表链接。 Hibernate将使用Join Table来填充域类中的Super hero列表我们将在下一步继续查看。 域类和Hibernate映射 与主要拥有实体正义联盟实体链接的联接表主要只有两个域类。 因此让我们继续看看如何使用注释构造域类。 package com.justice.league.domain;import java.io.Serializable;import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table;import org.hibernate.annotations.Type;Entity Table(name SuperHero) public class SuperHero implements Serializable {/*** */private static final long serialVersionUID -6712720661371583351L;IdGeneratedValue(strategy GenerationType.AUTO)Column(name super_hero_id)private Long superHeroId;Column(name super_hero_name)private String name;Column(name power_description)private String powerDescription;Type(type yes_no)Column(name isAwesome)private boolean isAwesome;public Long getSuperHeroId() {return superHeroId;}public void setSuperHeroId(Long superHeroId) {this.superHeroId superHeroId;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getPowerDescription() {return powerDescription;}public void setPowerDescription(String powerDescription) {this.powerDescription powerDescription;}public boolean isAwesome() {return isAwesome;}public void setAwesome(boolean isAwesome) {this.isAwesome isAwesome;}} 因为我将MySQL用作主要数据库所以我将GeneratedValue策略用作GenerationType.AUTO 只要创建了新的超级英雄它将自动进行递增。 所有其他映射都为大家所熟悉除了 我们将布尔值映射到数据库中Char字段的最后一个变量。 我们在数据库字段中使用Hibernate的Type批注将truefalse表示为YN。 Hibernate有许多Type实现您可以在这里阅读。 在这种情况下我们使用了这种类型。 好了现在我们有了代表超级英雄的班级让我们继续看一下我们的正义联盟领域的模样这将保留所有对联盟表示忠诚的超级英雄。 package com.justice.league.domain;import java.io.Serializable; import java.util.ArrayList; import java.util.List;import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.OneToMany; import javax.persistence.Table;Entity Table(name JusticeLeague) public class JusticeLeague implements Serializable {/*** */private static final long serialVersionUID 763500275393020111L;IdGeneratedValue(strategy GenerationType.AUTO)Column(name justice_league_id)private Long justiceLeagueId;Column(name justice_league_moto)private String justiceLeagueMoto;Column(name number_of_members)private Integer numberOfMembers;OneToMany(cascade { CascadeType.ALL }, fetch FetchType.EAGER, orphanRemoval true)JoinTable(name JUSTICE_LEAGUE_SUPER_HERO, joinColumns { JoinColumn(name justice_league_id) }, inverseJoinColumns { JoinColumn(name super_hero_id) })private ListSuperHero superHeroList new ArrayListSuperHero(0);public Long getJusticeLeagueId() {return justiceLeagueId;}public void setJusticeLeagueId(Long justiceLeagueId) {this.justiceLeagueId justiceLeagueId;}public String getJusticeLeagueMoto() {return justiceLeagueMoto;}public void setJusticeLeagueMoto(String justiceLeagueMoto) {this.justiceLeagueMoto justiceLeagueMoto;}public Integer getNumberOfMembers() {return numberOfMembers;}public void setNumberOfMembers(Integer numberOfMembers) {this.numberOfMembers numberOfMembers;}public ListSuperHero getSuperHeroList() {return superHeroList;}public void setSuperHeroList(ListSuperHero superHeroList) {this.superHeroList superHeroList;}} 这里要注意的重要事实是注释OneToManycascade {CascadeType.ALL}fetch FetchType.EAGERorphanRemoval true 。 在这里我们设置了orphanRemoval true 。 那到底是做什么的呢 好吧假设您的联赛中有一群超级英雄。 并说一个超级英雄是干草堆。 所以我们需要从联盟中移除他/她。 使用JPA级联由于无法检测孤立记录因此这是不可能的 然后您将拥有删除了“超级英雄”的数据库而您的收藏中仍然有对它的引用。 在JPA 2.0之前您没有orphanRemoval支持并且是删除孤立记录的唯一方法 是要使用以下Hibernate特定或ORM特定注释现在已弃用 org.hibernate.annotations.Cascadeorg.hibernate.annotations.CascadeType.DELETE_ORPHAN 但是通过引入属性orphanRemoval我们现在能够通过JPA处理孤立记录的删除。 现在我们有了Domain类 DAO和服务类 为了保持良好的设计标准我将DAO数据访问对象层和服务层分开。 因此让我们看一下DAO的界面和实现。 请注意我有 通过HibernateDAOSupport使用了HibernateTemplate 从而避免了任何特定于Hibernate的细节并使用Spring以统一的方式访问所有内容。 package com.justice.league.dao;import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional;import com.justice.league.domain.JusticeLeague;Transactional(propagation Propagation.REQUIRED, readOnly false) public interface JusticeLeagueDAO {public void createOrUpdateJuticeLeagure(JusticeLeague league);public JusticeLeague retrieveJusticeLeagueById(Long id); } 在接口层中我已根据需要定义了事务处理。 这样做是为了使每当不需要事务时您都可以在该特定方法的方法级别定义它在更多情况下您将需要事务 除了数据检索方法。   根据JPA规范您需要一个有效的事务来执行插入/删除/更新功能 。 因此让我们看一下DAO的实现 package com.justice.league.dao.hibernate;import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional;import com.justice.league.dao.JusticeLeagueDAO; import com.justice.league.domain.JusticeLeague;Qualifier(valuejusticeLeagueHibernateDAO) public class JusticeLeagueHibernateDAOImpl extends HibernateDaoSupportimplements JusticeLeagueDAO {Overridepublic void createOrUpdateJuticeLeagure(JusticeLeague league) {if (league.getJusticeLeagueId() null) {getHibernateTemplate().persist(league);} else {getHibernateTemplate().update(league);}}Transactional(propagation Propagation.NOT_SUPPORTED, readOnly false) public JusticeLeague retrieveJusticeLeagueById(Long id){return getHibernateTemplate().get(JusticeLeague.class, id);}} 在这里我定义了一个Qualifier以让Spring知道这是DAO类的Hibernate实现。 请注意以休眠结尾的软件包名称。 在我看来这是一个很好的设计概念可遵循的将您的实现分离为 分开包装以保持设计整洁。 好的让我们继续进行服务层的实现。 在这种情况下服务层只是充当调用DAO方法的中介层。 但是在现实世界的应用程序中您可能会在服务层中进行其他验证与安全性相关的过程等。 package com.justice.league.service;import com.justice.league.domain.JusticeLeague;public interface JusticeLeagureService {public void handleJusticeLeagureCreateUpdate(JusticeLeague justiceLeague);public JusticeLeague retrieveJusticeLeagueById(Long id); }package com.justice.league.service.impl;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component;import com.justice.league.dao.JusticeLeagueDAO; import com.justice.league.domain.JusticeLeague; import com.justice.league.service.JusticeLeagureService;Component(justiceLeagueService) public class JusticeLeagureServiceImpl implements JusticeLeagureService {AutowiredQualifier(value justiceLeagueHibernateDAO)private JusticeLeagueDAO justiceLeagueDAO;Overridepublic void handleJusticeLeagureCreateUpdate(JusticeLeague justiceLeague) {justiceLeagueDAO.createOrUpdateJuticeLeagure(justiceLeague);}public JusticeLeague retrieveJusticeLeagueById(Long id){return justiceLeagueDAO.retrieveJusticeLeagueById(id);} } 这里没有什么要注意的。 首先 Component在春天上下文中将此服务实现与名称JusticeLeagueService绑定在一起以便我们可以将bean称为ID为JusticeLeagueService的bean 。 并且我们已经自动连接了JusticeLeagueDAO并定义了一个Qualifier以便它将绑定到Hibernate实现。 Qualifier的值应与我们在DAO Implementation类中为类级别Qualifier赋予的名称相同。 最后让我们看一下将所有这些连接在一起的Spring配置。 应用程序的Spring配置 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/tx xmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdcontext:component-scan base-packagecom.justice.league /context:annotation-config /tx:annotation-driven /bean idsessionFactoryclassorg.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBeanproperty namepackagesToScanlistvaluecom.justice.league.**.*/value/list/propertyproperty namehibernatePropertiespropsprop keyhibernate.dialectorg.hibernate.dialect.MySQLDialect/propprop keyhibernate.connection.driver_classcom.mysql.jdbc.Driver/propprop keyhibernate.connection.urljdbc:mysql://localhost:3306/my_test/propprop keyhibernate.connection.usernameroot/propprop keyhibernate.connection.passwordpassword/propprop keyhibernate.show_sqltrue/propprop keyhibernate.dialectorg.hibernate.dialect.MySQLDialect/prop/props/property/beanbean idjusticeLeageDAOclasscom.justice.league.dao.hibernate.JusticeLeagueHibernateDAOImplproperty namesessionFactory refsessionFactory //beanbean idtransactionManagerclassorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //bean/beans 请注意在我单独运行它的情况下我在此实例中使用了HibernateTransactionManager 。 如果你是 在应用服务器中运行它您几乎总是会使用JTA事务管理器。 为了简化起见我还使用了由hibernate自动创建表的方法。 packagesToScan属性指示扫描根包com.justice.league。**。*下的所有子包包括嵌套在其中的嵌套包为 扫描Entity注释的类。 我们还将会话工厂限制在了JusticeLeagueDAO上以便我们可以使用Hibernate Template。 为了进行测试您可以根据需要最初使用标签prop key “ hibernate.hbm2ddl.auto” create / prop 然后让hibernate为您创建表。 好了现在我们已经看到了应用程序的构建块让我们首先在正义联盟内创建一些超级英雄看看它们如何工作 一个简单的主类来展示所有工作原理 作为第一个示例让我们看看我们将如何通过几个超级英雄来维持正义联盟。 package com.test;import java.util.ArrayList; import java.util.List;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.justice.league.domain.JusticeLeague; import com.justice.league.domain.SuperHero; import com.justice.league.service.JusticeLeagureService;public class TestSpring {/*** param args*/public static void main(String[] args) {ApplicationContext ctx new ClassPathXmlApplicationContext(spring-context.xml);JusticeLeagureService service (JusticeLeagureService) ctx.getBean(justiceLeagueService);JusticeLeague league new JusticeLeague();ListSuperHero superHeroList getSuperHeroList();league.setSuperHeroList(superHeroList);league.setJusticeLeagueMoto(Guardians of the Galaxy);league.setNumberOfMembers(superHeroList.size());service.handleJusticeLeagureCreateUpdate(league);}private static ListSuperHero getSuperHeroList() {ListSuperHero superHeroList new ArrayListSuperHero();SuperHero superMan new SuperHero();superMan.setAwesome(true);superMan.setName(Clark Kent);superMan.setPowerDescription(Faster than a speeding bullet);superHeroList.add(superMan);SuperHero batMan new SuperHero();batMan.setAwesome(true);batMan.setName(Bruce Wayne);batMan.setPowerDescription(I just have some cool gadgets);superHeroList.add(batMan);return superHeroList;}} 如果我们进入数据库并进行检查我们将看到以下输出 mysql select * from superhero; -------------------------------------------------------------------------- | super_hero_id | isAwesome | super_hero_name | power_description | -------------------------------------------------------------------------- | 1 | Y | Clark Kent | Faster than a speeding bullet | | 2 | Y | Bruce Wayne | I just have some cool gadgets | --------------------------------------------------------------------------mysql select * from justiceleague; --------------------------------------------------------------- | justice_league_id | justice_league_moto | number_of_members | --------------------------------------------------------------- | 1 | Guardians of the Galaxy | 2 | --------------------------------------------------------------- 如您所见我们坚持了两位超级英雄并将他们与正义联盟联系在一起。 现在让我们看看下面的示例如何删除孤儿。 package com.test;import java.util.ArrayList; import java.util.List;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.justice.league.domain.JusticeLeague; import com.justice.league.domain.SuperHero; import com.justice.league.service.JusticeLeagureService;public class TestSpring {/*** param args*/public static void main(String[] args) {ApplicationContext ctx new ClassPathXmlApplicationContext(spring-context.xml);JusticeLeagureService service (JusticeLeagureService) ctx.getBean(justiceLeagueService);JusticeLeague league service.retrieveJusticeLeagueById(1l);ListSuperHero superHeroList league.getSuperHeroList();/*** Here we remove Batman(a.k.a Bruce Wayne) out of the Justice League* cos he aint cool no more*/for (int i 0; i superHeroList.size(); i) {SuperHero superHero superHeroList.get(i);if (superHero.getName().equalsIgnoreCase(Bruce Wayne)) {superHeroList.remove(i);break;}}service.handleJusticeLeagureCreateUpdate(league);}} 在这里我们首先通过主键检索正义联盟的记录。 然后我们循环浏览并从联盟中删除蝙蝠侠然后再次调用createOrUpdate方法。 当我们定义了删除孤儿时所有不在数据库列表中的超级英雄都将被删除。 再次如果查询数据库我们将看到蝙蝠侠已经按照以下说明被删除了 mysql select * from superhero; -------------------------------------------------------------------------- | super_hero_id | isAwesome | super_hero_name | power_description | -------------------------------------------------------------------------- | 1 | Y | Clark Kent | Faster than a speeding bullet | -------------------------------------------------------------------------- 就是这样了。 正义联盟Justice League如何使用休眠模式自动删除蝙蝠侠而无需费心自己做的故事。 接下来我们将期待美国队长如何使用休眠标准来构建灵活的查询以便找到可能的敌人。 小心 祝大家有美好的一天并感谢您的阅读 如果您有任何建议或意见请不要理会。 参考“ 通过示例进行休眠–第1部分除去孤儿”来自我们的JCG合作伙伴 Dinuka Arseculeratne在“ My Journey Through IT”博客中 相关文章 休眠陷阱 休眠自动提交命令强制MySQL在过多的磁盘I / O中运行 DataNucleus 3.0与Hibernate 3.5 Hibernate映射集合性能问题 Spring MVC3 Hibernate CRUD示例应用程序 Java教程和Android教程列表 翻译自: https://www.javacodegeeks.com/2011/11/hibernate-by-example-part-1-orphan.html
http://www.sadfv.cn/news/6640/

相关文章:

  • 我要建设公司网站湘潭做网站价格优选磐石网络
  • 品牌网站建设推广深圳云购网站制作
  • 用织梦后台修改网站logo安徽省建设厅网站备案
  • 美团网站做疏通广告河源建筑设计企业名录黄页
  • 蓝色网站源码黑客入侵网课
  • 深圳建网建网站广州机械加工
  • wordpress cdn厦门百度快照优化排名
  • 网站开发商品排序逻辑快速搭建展示型网站
  • 网上效果代码网站可以下载吗软文营销的特点
  • 友情网站制作wordpress菜单新窗口打开
  • 崇左市城市投资建设有限公司网站seo站长工具下载
  • 河南网站建设软件厦门 网站备案
  • 百度注册网站怎么弄减肥网站源码
  • 什么是响应式营销型网站建设东莞厚街天气
  • 网站里的动画是什么软件做的宁波网页设计哪家好
  • 营销型网站搭建百度网站大全旧版
  • 公司制作一个网站图书馆主题 wordpress
  • 专注高密做网站哪家好一般网站开发公司
  • 东源建设局网站推荐做网站的公司
  • 做网上推广网站凡科免费建微信小程序网站
  • 网站防红链接怎么做wordpress 走马灯
  • 网站产品展示单页模板课程网站建设简介
  • 甘肃省住房建设厅网站江门网站开发多少钱
  • 湛江免费网站制作企业网站seo名称
  • 付费资料网站开发wordpress some chinese please
  • 网站建设赚钱吗招聘设计师去哪个网站
  • 建立一个网站怎样赚钱做网站课程报告
  • 做甲方去哪个网站应聘辽宁建设执业继续教育协会网站
  • 猪八戒 网站开发支付做外汇网站代理赚钱吗
  • 四川建设招标网站首页有哪些网站是cms