JPA Advanced Mappings(映射)
JPA Advanced Mappings(映射)
JPA是一个使用java规范发布的库。因此,它支持所有面向对象的实体持久性概念。
原文链接:http://blogxinxiucan.sh1.newtouch.com/2017/07/30/JPA-Advanced-Mappings-映射/
继承策略
继承是面向对象语言的核心概念,因此我们可以在实体之间使用继承关系或策略。JPA支持三种类型的继承策略,如SINGLE_TABLE,JOINED_TABLE和TABLE_PER_CONCRETE_CLASS。
Staff, TeachingStaff, NonTeachingStaff关系:
在上图中,Staff是一个实体,TeachingStaff和NonTeachingStaff是员工的子实体。在这里我们将讨论上述三个继承的策略。
单表策略
单表策略采用所有类字段(超类和子类),并将其映射到称为SINGLE_TABLE策略的单个表中。鉴别器值在区分一个表中三个实体的值时起关键作用。
让我们考虑上面的例子,TeachingStaff和NonTeachingStaff是类员工的子类。提醒继承的概念(是通过子类继承超类的属性的机制),因此sid,sname是属于TeachingStaff和NonTeachingStaff的字段。创建一个JPA项目。本项目的所有模块如下:
创建实体
在“src”
包下创建一个名为“com.tutorialspoint.eclipselink.entity”
的包。在给定的包下创建一个名为Staff.java的新Java类。Staff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import java.io.Serializable;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
@Entity
@Table
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn( name = "type" )
public class Staff implements Serializable {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
private int sid;
private String sname;
public Staff( int sid, String sname ) {
super( );
this.sid = sid;
this.sname = sname;
}
public Staff( ) {
super( );
}
public int getSid( ) {
return sid;
}
public void setSid( int sid ) {
this.sid = sid;
}
public String getSname( ) {
return sname;
}
public void setSname( String sname ) {
this.sname = sname;
}
}
在上述代码中,@DescriminatorColumn指定字段名称(type),其值显示剩余的(Teaching and NonTeachingStaff)字段。
在com.tutorialspoint.eclipselink.entity包下创建一个名为TeachingStaff.java的 Staff类的子类(class)。TeachingStaff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue( value="TS" )
public class TeachingStaff extends Staff {
private String qualification;
private String subjectexpertise;
public TeachingStaff( int sid, String sname,
String qualification,String subjectexpertise ) {
super( sid, sname );
this.qualification = qualification;
this.subjectexpertise = subjectexpertise;
}
public TeachingStaff( ) {
super( );
}
public String getQualification( ){
return qualification;
}
public void setQualification( String qualification ){
this.qualification = qualification;
}
public String getSubjectexpertise( ) {
return subjectexpertise;
}
public void setSubjectexpertise( String subjectexpertise ){
this.subjectexpertise = subjectexpertise;
}
}
在com.tutorialspoint.eclipselink.entity包下创建一个名为NonTeachingStaff.java的 Staff类的子类(class)。NonTeachingStaff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue( value = "NS" )
public class NonTeachingStaff extends Staff {
private String areaexpertise;
public NonTeachingStaff( int sid, String sname, String areaexpertise ) {
super( sid, sname );
this.areaexpertise = areaexpertise;
}
public NonTeachingStaff( ) {
super( );
}
public String getAreaexpertise( ) {
return areaexpertise;
}
public void setAreaexpertise( String areaexpertise ){
this.areaexpertise = areaexpertise;
}
}
persistence.xml中
Persistence.xml文件包含实体类的数据库和注册信息的配置信息。xml文件显示如下:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="Eclipselink_JPA" transaction-type="RESOURCE_LOCAL">
<class>com.tutorialspoint.eclipselink.entity.Staff</class>
<class>com.tutorialspoint.eclipselink.entity.NonTeachingStaff</class>
<class>com.tutorialspoint.eclipselink.entity.TeachingStaff</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpadb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
Service class
服务类是业务组件的实现部分。在名为'com.tutorialspoint.eclipselink.service'的'src'包下创建一个包。
在给定的包下创建一个名为SaveClient.java的类来存储Staff,TeachingStaff和NonTeachingStaff类字段。SaveClient类显示如下:
package com.tutorialspoint.eclipselink.service;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.tutorialspoint.eclipselink.entity.NonTeachingStaff;
import com.tutorialspoint.eclipselink.entity.TeachingStaff;
public class SaveClient {
public static void main( String[ ] args ) {
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );
EntityManager entitymanager = emfactory.createEntityManager( );
entitymanager.getTransaction( ).begin( );
//Teaching staff entity
TeachingStaff ts1=new TeachingStaff(1,"Gopal","MSc MEd","Maths");
TeachingStaff ts2=new TeachingStaff(2, "Manisha", "BSc BEd", "English");
//Non-Teaching Staff entity
NonTeachingStaff nts1=new NonTeachingStaff(3, "Satish", "Accounts");
NonTeachingStaff nts2=new NonTeachingStaff(4, "Krishna", "Office Admin");
//storing all entities
entitymanager.persist(ts1);
entitymanager.persist(ts2);
entitymanager.persist(nts1);
entitymanager.persist(nts2);
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
}
}
编译和执行上述程序后,您将在Eclipse IDE的控制面板中收到通知。检查MySQL工作台的输出。表格格式的输出如下所示:
Sid | Type | Sname | Areaexpertise | Qualification | Subjectexpertise |
---|---|---|---|---|---|
1 | TS | Gopal | - | MSC MED | Maths |
2 | TS | Manisha | - | BSC BED | English |
3 | NS | Satish | Accounts | ||
4 | NS | Krishna | Office Admin |
最后,您将获得包含所有三类字段的单表,并与名为“Type”(字段)的discriminator列不同。
加盟表策略
加入表策略是共享引用的列,其中包含唯一值以加入表并进行简单的事务。让我们考虑与上述相同的例子。
创建JPA项目。所有项目模块如下所示:
创建实体
在“src”包下创建一个名为“com.tutorialspoint.eclipselink.entity” 的包。在给定的包下创建一个名为Staff.java的新Java类。Staff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
@Entity
@Table
@Inheritance( strategy = InheritanceType.JOINED )
public class Staff implements Serializable {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
private int sid;
private String sname;
public Staff( int sid, String sname ) {
super( );
this.sid = sid;
this.sname = sname;
}
public Staff( ) {
super( );
}
public int getSid( ) {
return sid;
}
public void setSid( int sid ) {
this.sid = sid;
}
public String getSname( ) {
return sname;
}
public void setSname( String sname ) {
this.sname = sname;
}
}
在com.tutorialspoint.eclipselink.entity包下创建一个名为TeachingStaff.java的 Staff类的子类(class)。TeachingStaff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@PrimaryKeyJoinColumn(referencedColumnName="sid")
public class TeachingStaff extends Staff {
private String qualification;
private String subjectexpertise;
public TeachingStaff( int sid, String sname,
String qualification,String subjectexpertise ) {
super( sid, sname );
this.qualification = qualification;
this.subjectexpertise = subjectexpertise;
}
public TeachingStaff( ) {
super( );
}
public String getQualification( ){
return qualification;
}
public void setQualification( String qualification ){
this.qualification = qualification;
}
public String getSubjectexpertise( ) {
return subjectexpertise;
}
public void setSubjectexpertise( String subjectexpertise ){
this.subjectexpertise = subjectexpertise;
}
}
在com.tutorialspoint.eclipselink.entity包下创建一个名为NonTeachingStaff.java的 Staff类的子类(class)。NonTeachingStaff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@PrimaryKeyJoinColumn(referencedColumnName="sid")
public class NonTeachingStaff extends Staff {
private String areaexpertise;
public NonTeachingStaff( int sid, String sname, String areaexpertise ) {
super( sid, sname );
this.areaexpertise = areaexpertise;
}
public NonTeachingStaff( ) {
super( );
}
public String getAreaexpertise( ) {
return areaexpertise;
}
public void setAreaexpertise( String areaexpertise ) {
this.areaexpertise = areaexpertise;
}
}
persistence.xml中
Persistence.xml文件包含实体类的数据库和注册信息的配置信息。xml文件显示如下:
<?xml version = "1.0" encoding = "UTF-8"?>
<persistence version = "2.0" xmlns = "http://java.sun.com/xml/ns/persistence"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name = "Eclipselink_JPA" transaction-type = "RESOURCE_LOCAL">
<class>com.tutorialspoint.eclipselink.entity.Staff</class>
<class>com.tutorialspoint.eclipselink.entity.NonTeachingStaff</class>
<class>com.tutorialspoint.eclipselink.entity.TeachingStaff</class>
<properties>
<property name = "javax.persistence.jdbc.url" value = "jdbc:mysql://localhost:3306/jpadb"/>
<property name = "javax.persistence.jdbc.user" value = "root"/>
<property name = "javax.persistence.jdbc.password" value = "root"/>
<property name = "javax.persistence.jdbc.driver" value = "com.mysql.jdbc.Driver"/>
<property name = "eclipselink.logging.level" value = "FINE"/>
<property name = "eclipselink.ddl-generation" value = "create-tables"/>
</properties>
</persistence-unit>
</persistence>
服务类
服务类是业务组件的实现部分。在名为'com.tutorialspoint.eclipselink.service'的'src'包下创建一个包。
在给定的包下创建一个名为SaveClient.java的类来存储Staff,TeachingStaff和NonTeachingStaff类字段。然后SaveClient类如下:
package com.tutorialspoint.eclipselink.service;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.tutorialspoint.eclipselink.entity.NonTeachingStaff;
import com.tutorialspoint.eclipselink.entity.TeachingStaff;
public class SaveClient {
public static void main( String[ ] args ) {
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );
EntityManager entitymanager = emfactory.createEntityManager( );
entitymanager.getTransaction( ).begin( );
//Teaching staff entity
TeachingStaff ts1 = new TeachingStaff(1,"Gopal","MSc MEd","Maths");
TeachingStaff ts2 = new TeachingStaff(2, "Manisha", "BSc BEd", "English");
//Non-Teaching Staff entity
NonTeachingStaff nts1 = new NonTeachingStaff(3, "Satish", "Accounts");
NonTeachingStaff nts2 = new NonTeachingStaff(4, "Krishna", "Office Admin");
//storing all entities
entitymanager.persist(ts1);
entitymanager.persist(ts2);
entitymanager.persist(nts1);
entitymanager.persist(nts2);
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
}
}
编译和执行上述程序后,您将在Eclipse IDE的控制面板中收到通知。输出检查MySQL工作台如下:
这里创建了三个表格,表格格式的员工表格的结果如下所示:
Sid | Dtype | Sname |
---|---|---|
1 | TeachingStaff | Gopal |
2 | TeachingStaff | Manisha |
3 | NonTeachingStaff | Satish |
4 | NonTeachingStaff | Krishna |
TeachingStaff表的结果如表格所示:
Sid | Qualification | Subjectexpertise |
---|---|---|
1 | MSC MED | Maths |
2 | BSC BED | English |
在上表中sid是外键(参考字段表单staff表)NonTeachingStaff表的结果如表格所示:
Sid | Areaexpertise |
---|---|
3 | Accounts |
4 | Office Admin |
最后,这三个表分别使用它们的字段创建,SID字段由所有三个表共享。在员工表SID中是主键,在剩余的(TeachingStaff和NonTeachingStaff)表中SID是外键。
每个类策略表
每个类策略的表是为每个子实体创建一个表。工作人员表将被创建,但它将包含空记录。Staff表的字段值必须由TeachingStaff和NonTeachingStaff表共享。
让我们考虑与上述相同的例子。本项目的所有模块如下所示:
创建实体
在“src”包下创建一个名为“com.tutorialspoint.eclipselink.entity” 的包。在给定的包下创建一个名为Staff.java的新Java类。Staff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
@Entity
@Table
@Inheritance( strategy = InheritanceType.TABLE_PER_CLASS )
public class Staff implements Serializable {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
private int sid;
private String sname;
public Staff( int sid, String sname ) {
super( );
this.sid = sid;
this.sname = sname;
}
public Staff( ) {
super( );
}
public int getSid( ) {
return sid;
}
public void setSid( int sid ) {
this.sid = sid;
}
public String getSname( ) {
return sname;
}
public void setSname( String sname ) {
this.sname = sname;
}
}
在com.tutorialspoint.eclipselink.entity包下创建一个名为TeachingStaff.java的 Staff类的子类(class)。TeachingStaff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
public class TeachingStaff extends Staff {
private String qualification;
private String subjectexpertise;
public TeachingStaff( int sid, String sname, String qualification, String subjectexpertise ) {
super( sid, sname );
this.qualification = qualification;
this.subjectexpertise = subjectexpertise;
}
public TeachingStaff( ) {
super( );
}
public String getQualification( ){
return qualification;
}
public void setQualification( String qualification ) {
this.qualification = qualification;
}
public String getSubjectexpertise( ) {
return subjectexpertise;
}
public void setSubjectexpertise( String subjectexpertise ){
this.subjectexpertise = subjectexpertise;
}
}
在com.tutorialspoint.eclipselink.entity包下创建一个名为NonTeachingStaff.java的 Staff类的子类(class)。NonTeachingStaff实体类显示如下:
package com.tutorialspoint.eclipselink.entity;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
public class NonTeachingStaff extends Staff {
private String areaexpertise;
public NonTeachingStaff( int sid, String sname, String areaexpertise ) {
super( sid, sname );
this.areaexpertise = areaexpertise;
}
public NonTeachingStaff( ) {
super( );
}
public String getAreaexpertise( ) {
return areaexpertise;
}
public void setAreaexpertise( String areaexpertise ) {
this.areaexpertise = areaexpertise;
}
}
persistence.xml中
Persistence.xml文件包含实体类的数据库和注册信息的配置信息。xml文件显示如下:
<?xml version="1.0" encoding = "UTF-8"?>
<persistence version = "2.0" xmlns = "http://java.sun.com/xml/ns/persistence"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name = "Eclipselink_JPA" transaction-type = "RESOURCE_LOCAL">
<class>com.tutorialspoint.eclipselink.entity.Staff</class>
<class>com.tutorialspoint.eclipselink.entity.NonTeachingStaff</class>
<class>com.tutorialspoint.eclipselink.entity.TeachingStaff</class>
<properties>
<property name = "javax.persistence.jdbc.url" value = "jdbc:mysql://localhost:3306/jpadb"/>
<property name = "javax.persistence.jdbc.user" value = "root"/>
<property name = "javax.persistence.jdbc.password" value = "root"/>
<property name = "javax.persistence.jdbc.driver" value = "com.mysql.jdbc.Driver"/>
<property name = "eclipselink.logging.level" value = "FINE"/>
<property name = "eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
服务类
服务类是业务组件的实现部分。在名为'com.tutorialspoint.eclipselink.service'的'src'包下创建一个包。
在给定的包下创建一个名为SaveClient.java的类来存储Staff,TeachingStaff和NonTeachingStaff类字段。SaveClient类显示如下:
package com.tutorialspoint.eclipselink.service;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.tutorialspoint.eclipselink.entity.NonTeachingStaff;
import com.tutorialspoint.eclipselink.entity.TeachingStaff;
public class SaveClient {
public static void main( String[ ] args ) {
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );
EntityManager entitymanager = emfactory.createEntityManager( );
entitymanager.getTransaction( ).begin( );
//Teaching staff entity
TeachingStaff ts1 = new TeachingStaff(1,"Gopal","MSc MEd","Maths");
TeachingStaff ts2 = new TeachingStaff(2, "Manisha", "BSc BEd", "English");
//Non-Teaching Staff entity
NonTeachingStaff nts1 = new NonTeachingStaff(3, "Satish", "Accounts");
NonTeachingStaff nts2 = new NonTeachingStaff(4, "Krishna", "Office Admin");
//storing all entities
entitymanager.persist(ts1);
entitymanager.persist(ts2);
entitymanager.persist(nts1);
entitymanager.persist(nts2);
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
}
}
编译和执行上述程序后,您将在Eclipse IDE的控制面板中收到通知。对于输出,检查MySQL工作台如下:
这里创建了三个表,Staff表包含空记录。
TeachingStaff的结果如表格所示:
Sid | Qualification | Sname | Subjectexpertise |
---|---|---|---|
1 | MSC MED | Gopal | Maths |
2 | BSC BED | Manisha | English |
上表TeachingStaff包含员工和教学实体的领域。
NonTeachingStaff的结果如表格所示:
Sid | Areaexpertise | Sname |
---|---|---|
3 | Accounts | Satish |
4 | Office Admin | Krishna |
以上表格NonTeachingStaff包含Staff和NonTeachingStaff实体的字段。
公众号:it全能程序猿
JPA Advanced Mappings(映射)的更多相关文章
- JPA实体继承映射
注意:据说,在本文所指的实体是@Entity注解的类. JPA在对象 - 关系映射通常情况下一个实体对应表,不管是什么这两个实体之间的关系.假设两个实体之间的继承关系.那么它是如何映射? JPA实体支 ...
- JPA实体关系映射:@ManyToMany多对多关系、@OneToMany@ManyToOne一对多多对一关系和@OneToOne的深度实例解析
JPA实体关系映射:@ManyToMany多对多关系.@OneToMany@ManyToOne一对多多对一关系和@OneToOne的深度实例解析 今天程序中遇到的错误一 org.hibernate.A ...
- JPA 简单实体映射和EntityManagerAPI
[常用注解] 使用JPA 指定映射关系时,有两种方式,一种是使用xml 方式,另一种是注解方式,笔者推荐使用注解方式.在JPA 映射简单实体时,常用的注解如下: @Entity:修饰实体类对象,表示该 ...
- JPA 对象关系映射之关联关系映射策略
关联关系映射 关联关系映射,是映射关系中比较复杂的一种映射关系,总的说来有一对一.一对多和多对多几种关系.细分起来他们又有单向和双向之分.下面我们逐一介绍一下. 回页首 单向 OneToOne 单向一 ...
- JPA 对象关系映射总结(一)---persistence.xml 文件配置要点
1. <property name="hibernate.hbm2ddl.auto" value="update"/>,这里表示的 功能是: 自动创 ...
- Elastic Stack 笔记(五)Elasticsearch5.6 Mappings 映射
博客地址:http://www.moonxy.com 一.前言 关系型数据库对我们来说都很熟悉,Elasticsearch 也可以看成是一种数据库,所以我们经常将关系型数据库中的概念和 Elastic ...
- Spring Boot 入门系列(二十八) JPA 的实体映射关系,一对一,一对多,多对多关系映射!
前面讲了Spring Boot 使用 JPA,实现JPA 的增.删.改.查的功能,同时也介绍了JPA的一些查询,自定义SQL查询等使用.JPA使用非常简单,功能非常强大的ORM框架,无需任何数据访问层 ...
- Spring Data JPA:关联映射操作
1.一对一的关系关联 需求:用户和角色一对一关联 package com.example.jpa.pojo; import javax.persistence.*; @Entity @Table(na ...
- jpa多对一映射
1.插入 建一个部门类Dept和一个员工类Emp: Emp对Dept是多对一的关系:因为一个部门有多个员工,而一个员工只有一个部门: Emp类中添加一个Dept的属性: @ManyToOne注解表 ...
随机推荐
- Java集合源码分析之 LinkedList
一.简介 LinkedList是一个常用的集合类,用于顺序存储元素.LinkedList经常和ArrayList一起被提及.大部分人应该都知道ArrayList内部采用数组保存元素,适合用于随机访问比 ...
- thinkphp3.2.3 版本使用redis缓存添加认证
我在使用thinkphp3.2.3的时候 发现如果是使用redis缓存 设置了认证的redis能连接成功 却无法 set 操作 ,检查发现是没有认证导致的 $redis->auth这一步没有, ...
- Builder模式详解及其在Android开发中的应用
一.引言 在Android开发中,采用Builder模式的代码随处可见,比如说Android系统对话框AlertDialog的使用或者是Android中的通知栏(Notification)的使用,又比 ...
- Greenplum——大数据时代高性能的数据仓库与BI应用平台
一. Greenplum简介 大数据是个炙手可热的词,各行各业都在谈.一谈到大数据,好多人认为就是Hadoop.实际上Hadoop只是大数据若干处理方案中的一个.现在的SQL.NoSQL.NewSQL ...
- 有关ArrayList常用方法的源码解析
我相信几乎所有的同学在大大小小的笔试.面试过程中都会被问及ArrayList与LinkedList之间的异同点.稍有准备的人这些问题早已烂熟于心,前者基于数组实现,后者基于链表实现:前者随机方法速度快 ...
- 玩转UITableView系列(一)--- 解耦封装、简化代码、适者生存!
UITableView这个iOS开发中永远绕不开的UIView,那么就不可避免的要在多个页面多种场景下反复摩擦UITableView,就算是刚跳进火坑不久的iOS Developer也知道实现UITa ...
- 如何用JavaScript复制到剪贴板
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- eclipse在多modules项目结构下避免模块间依赖引用的场景
这个在单一classLoader时,不会有问题.如果多classloader下会有问题. 假设工程有两个模块,module2 依赖module1 当我们执行mvc eclipse:eclipse后,然 ...
- js代码风格之链式结构
<div class="box"> <ul class="menu"> <li class="level1"& ...
- IE的hack问题浅谈
*我一直以为是IE7的专属选择. 开始,我以为是bug ,怎么可能会有+号.一定是哪位同事写错了.找了度娘才知道自己的不足.原来也是可以的. 后来,通过ie8和ie7来调整自己的css.也感觉不用ha ...