ManyToMany单向、双向:@JoinTable的使用

目录
  • ManyToMany单向、双向:@JoinTable使用
    • 一、manytomany单向
    • 二、manytomany双向
  • @ManyToMany(多对多关系)使用小结

ManyToMany单向、双向:@JoinTable使用

一、manytomany单向

单向是指类层面,在下面例子中老师类可以知道要教哪些学生,学生不知被哪些老师教

**需要用到连接表**@JoinTable(name="t_s",
joinColumns={@JoinColumn(name="teacher_id")},inverseJoinColumns={@JoinColumn(name="student_id")}
)

也可以不用连接表,但是若不用连接表,表名、列名规则:

  • 在student表中没有写外键则会用对方的表名_主键名
  • 在teacher表中有外键,则会s_id(也是student的主键名)
  • 表名是student_teacher

student类

@Entity
public class student {
    private int id;
    private String name;
    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

Teacher类

@Entity
public class teacher {
    private int id;
    private String name;
    private Set<student> s=new HashSet<student>();
    @Id //必须加在getId上面
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @ManyToMany
    @JoinTable(name="t_s",
    joinColumns={@JoinColumn(name="teacher_id")},inverseJoinColumns={@JoinColumn(name="student_id")}
    )//将会以上两个字段为联合主键
    //定义中间表的名称,列名:joinColumns,inverseJoinColumns是预防组合主键的时候。
    public Set<student> getS() {
        return s;
    }
    public void setS(Set<student> s) {
        this.s = s;
    }
}

二、manytomany双向

也可以用@JoinTable对连接表字段名进行修改

@Entity
public class student {
    private int id;
    private String name;
    private Set<teacher> ts=new HashSet<teacher>();
    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @ManyToMany
    @JoinTable(name="t_s",
    joinColumns={@JoinColumn(name="teacher_id")},inverseJoinColumns={@JoinColumn(name="student_id")}
    )
    public Set<teacher> getTs() {
        return ts;
    }
    public void setTs(Set<teacher> ts) {
        this.ts = ts;
    }
}
@Entity
public class teacher {
    private int id;
    private String name;
    private Set<student> s=new HashSet<student>();
    @Id //必须加在getId上面
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @ManyToMany(mappedBy="ts")
    //定义中间表的名称,列名:joinColumns,inverseJoinColumns是预防组合主键的时候。
    public Set<student> getS() {
        return s;
    }
    public void setS(Set<student> s) {
        this.s = s;
    }
}

@ManyToMany(多对多关系)使用小结

DeviceGroup类

package com.sunwave.grouping.domain;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
@Entity
@Table(name = "device_group")
public class DeviceGroup implements Serializable{
    /**
	 *
	 */
	private static final long serialVersionUID = 1L;
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
   /* @Column(name="group_id")*/
    private long groupId;
    @Column(name="group_name")
    private String groupName;
    @Column(name="description")
    private String description;//自动在数据库里生成了group_has_element表,该表包括group_id和element_id两个字段,该表主要是用于存储device_group表和ne_element表的对应关系。
    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)//表的关联,生成一个group_has_element中间表。
    @JoinTable(name = "group_has_element",joinColumns = {@JoinColumn(name = "group_id",referencedColumnName = "groupId")}
    ,inverseJoinColumns = {@JoinColumn(name = "element_id",referencedColumnName = "neNeid")})
    private List<NeElement> elementList;

    public List<NeElement> getElementList() {
		return elementList;
	}
	public void setElementList(List<NeElement> elementList) {
		this.elementList = elementList;
	}
	public long getGroupId() {
		return groupId;
	}
	public void setGroupId(long groupId) {
		this.groupId = groupId;
	}
	public String getGroupName() {
		return groupName;
	}
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	@Override
	public String toString() {
		return "DeviceGroup [groupId=" + groupId + ", groupName=" + groupName + ", description=" + description
				+ ", elementList=" + elementList + "]";
	}

}

NeElement 类

package com.sunwave.grouping.domain;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 * @author lfw
 * @date   2020年8月3日
 * @time   下午6:44:54
 *
 */
@Entity
@Table(name = "ne_element")
public class NeElement implements Serializable{
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long neNeid; //设备唯一标识
	private String coonReqUrl; //设备连接URL
	private String serialNumber; //设备序列号
	private String deviceIp;  //设备IP
	private Long modelId;//modelName对应的id
	private String description;//描述
	private String manufacturer;//制造商
	private String softwareVersion;//软件版本
	private Date creationTime;//创建时间
	private Date lastBootstrapTime;
	private Date lastConnTime;//最后连接时间
	private Date updateTime;//更新时间
	private String oui;//oui
	private String product;
	private Boolean authRequirement;//是否需要认证
	private String dialectIP;
	private String updateUser;//更新用户
	private String macAddress;//mac地址
	private Integer onlineStatus;//在线状态
	private Integer sessionStatus;//会话状态
   @ManyToMany(mappedBy = "elementList")
	private List<DeviceGroup> deviceGroupList;
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getManufacturer() {
		return manufacturer;
	}
	public void setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
	}
	public String getSoftwareVersion() {
		return softwareVersion;
	}
	public void setSoftwareVersion(String softwareVersion) {
		this.softwareVersion = softwareVersion;
	}
	public Date getLastConnTime() {
		return lastConnTime;
	}
	public void setLastConnTime(Date lastConnTime) {
		this.lastConnTime = lastConnTime;
	}
	public Long getModelId() {
		return modelId;
	}
	public void setModelId(Long modelId) {
		this.modelId = modelId;
	}
	public Long getNeNeid() {
		return neNeid;
	}
	public void setNeNeid(Long neNeid) {
		this.neNeid = neNeid;
	}
	public String getCoonReqUrl() {
		return coonReqUrl;
	}
	public void setCoonReqUrl(String coonReqUrl) {
		this.coonReqUrl = coonReqUrl;
	}
	public String getDeviceIp() {
		return deviceIp;
	}
	public void setDeviceIp(String deviceIp) {
		this.deviceIp = deviceIp;
	}
	public String getSerialNumber() {
		return serialNumber;
	}
	public void setSerialNumber(String serialNumber) {
		this.serialNumber = serialNumber;
	}
	public Date getCreationTime() {
		return creationTime;
	}
	public void setCreationTime(Date creationTime) {
		this.creationTime = creationTime;
	}
	public Date getLastBootstrapTime() {
		return lastBootstrapTime;
	}
	public void setLastBootstrapTime(Date lastBootstrapTime) {
		this.lastBootstrapTime = lastBootstrapTime;
	}
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	public String getOui() {
		return oui;
	}
	public void setOui(String oui) {
		this.oui = oui;
	}
	public String getProduct() {
		return product;
	}
	public void setProduct(String product) {
		this.product = product;
	}
	public Boolean getAuthRequirement() {
		return authRequirement;
	}
	public void setAuthRequirement(Boolean authRequirement) {
		this.authRequirement = authRequirement;
	}
	public String getDialectIP() {
		return dialectIP;
	}
	public void setDialectIP(String dialectIP) {
		this.dialectIP = dialectIP;
	}
	public String getUpdateUser() {
		return updateUser;
	}
	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}
	public String getMacAddress() {
		return macAddress;
	}
	public void setMacAddress(String macAddress) {
		this.macAddress = macAddress;
	}
	public Integer getOnlineStatus() {
		return onlineStatus;
	}
	public void setOnlineStatus(Integer onlineStatus) {
		this.onlineStatus = onlineStatus;
	}
	public Integer getSessionStatus() {
		return sessionStatus;
	}
	public void setSessionStatus(Integer sessionStatus) {
		this.sessionStatus = sessionStatus;
	}
}

以上为多对多关系的使用,大家可以参考,本人在使用过程中遇到以下报错信息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unable to map collection com.sunwave.grouping.domain.DeviceGroup.elementList
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1694) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1087) ~[spring-context-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
 at com.sunwave.Application.main(Application.java:26) [classes/:na]
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
 at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
 at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.8.RELEASE.jar:2.0.8.RELEASE]
Caused by: org.hibernate.AnnotationException: Unable to map collection com.sunwave.grouping.domain.DeviceGroup.elementList
 at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1621) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1352) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:810) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:735) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1640) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1608) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1753) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1690) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
 ... 21 common frames omitted
Caused by: org.hibernate.cfg.RecoverableException: Unable to find column with logical name: groupId in org.hibernate.mapping.Table(device_group) and its related supertables and secondary tables
 at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:837) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:244) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1611) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 ... 37 common frames omitted
Caused by: org.hibernate.MappingException: Unable to find column with logical name: groupId in org.hibernate.mapping.Table(device_group) and its related supertables and secondary tables
 at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:832) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
 ... 39 common frames omitted

检查了实体类和数据库发现没有什么错,原来是因为我的实体类里的groupId上用了/*@Column(name=“group_id”)注解,如下把该注解注释掉或者删除掉就可以了。

/* @Column(name="group_id")*/ private long groupId;

其他关于@ManyToMany(多对多关系)的使用可以去百度再看看,本人就不多说了。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • 关于@OnetoMany关系映射的排序问题,使用注解@OrderBy

    目录 Spring里面一对多的关系可以用@OnetoMany注解来实现 来看看我的这个例子 看一下具体是怎么使用 最后我的代码 Entity One-to-Many 排序设置 Spring里面一对多的关系可以用@OnetoMany注解来实现 然后在实际使用中,如果要对从属对象按条件排序该怎么处理呢?可以用注解来实现的也就是@OrderBy 来看看我的这个例子 一个Product对象,里面有个OnetoMany关系对应到多张图片,然后我这个图片在后台要支持排序,所以我就在Picture这个类里面加

  • spring jpa ManyToMany原理及用法详解

    1.java和jpa 中所有的关系都是单向的.这个关系数据库不同,关系数据库,通过外键定义并查询,使得反向查询总是存在的. 2.JPA还定义了一个OneToMany关系,它与ManyToMany关系类似,但反向关系(如果已定义)是ManyToOne关系. OneToMany与JPA中ManyToMany关系的主要区别在于,ManyToMany总是使用中间关系连接表来存储关系, OneToMany可以使用连接表或者目标对象的表引用中的外键源对象表的主键. @OneToMany(cascade =

  • Mybatis中的mapper模糊查询语句LIKE

    目录 Mybatis mapper模糊查询语句LIKE mapper 模糊查询语句报错 Mybatis mapper模糊查询语句LIKE 最近做学校安排的课程设计作业,用到SSM框架,在自己写mapper代码是遇到了模糊查询的问题 困扰好久 下面是我解决这个问题的方法,其他网上好多方法我尝试过却没有实现 下面试sql语句 select * from goodsinfo where goodsname like '%' #{goodsname} '%' 注意代码中的空格 空格 空格 #{ } 方式

  • 详谈jpa中表的@OneToMany等关联关系

    目录 一.@OneToOne关系映射 1.通过外键的方式 2.通过关联表的方式来保存一对一的关系 二.@OneToMany 和 @ManyToOne 三.多对多 @ManyToMany 再次更新 One 端 Many 端 一.@OneToOne关系映射 JPA使用@OneToOne来标注一对一的关系. 实体 People :用户. 实体 Address:家庭住址. People 和 Address 是一对一的关系. 这里用两种方式描述JPA的一对一关系. 一种是通过外键的方式(一个实体通过外键关

  • 解决使用@ManyToMany查询数据时的死循环问题

    目录 使用@ManyToMany查询数据时的死循环 一.在Role中加上@JsonIgnore注解 二.将双向关联改为单向关联 单向多对多@ManyToMany的使用和理解 使用@ManyToMany查询数据时的死循环 初学使用spring data jpa,将问题记录 以User 和Role为例,两者为双向的多对多关系,即可以通过User查询到Role信息,也可以通过Role查询到User信息 首先要明白为什么会出现死循环这个问题,造成这个死循环的原因是因为查询User时,包含了Role属性,

  • ManyToMany单向、双向:@JoinTable的使用

    目录 ManyToMany单向.双向:@JoinTable使用 一.manytomany单向 二.manytomany双向 @ManyToMany(多对多关系)使用小结 ManyToMany单向.双向:@JoinTable使用 一.manytomany单向 单向是指类层面,在下面例子中老师类可以知道要教哪些学生,学生不知被哪些老师教 **需要用到连接表**@JoinTable(name="t_s", joinColumns={@JoinColumn(name="teacher

  • C++零基础精通数据结构之带头双向循环链表

    目录 与单链表的区别 代码的实现 接口 节点的构造 初始化链表 开辟节点 销毁链表 打印链表 尾插链表 尾删链表 头插链表 头删链表 查找链表 链表pos位置的删除 总结 与单链表的区别 单向/双向 单向:只有一个next指针,只指向下一位元素 双向:有两个指针,指向上一位和下一位元素,寻找前一节点和后一节点很便利 带头/不带头 带头:在本来的头结点之前还有一个哨兵卫节点作为头节点,它的址域指针指向头节点,值域不做使用 不带头:没有哨兵卫头节点,在尾删尾插等问题中要考虑头结点的情况(局限) 循环

  • SpringDataJpa多表操作的实现

    目录 Jpa表关系分析步骤 关联关系的注解 @JoinColumn定义外键关联的字段名称 @OneToOne一对一关联关系 @OrderBy关联查询的时候的排序 @JoinTable关联关系表 @ManyToMany多对多 数据库中的表存在着多种关系,一对一,一对多,多对多 Jpa表关系分析步骤 开发过程中会有很多多表的操作,他们之间有着各种关系,在Jpa这种实现来了orm思想的框架中我们可以通过操作实体类来操作数据库,我们来连接下jap如何配置实体类来实现这种功能 确定表之间的关系 在数据库实

  • socket.io学习教程之基础介绍(一)

    前言 Web端与服务器间的实时数据传输的是一个很重要的需求,但最早只能通过AJAX轮询询实现.在WebSocket标准没有推出之前,AJAX轮询是唯一可行的方式(通过Flash浏览器也可以,但这里不做讨论).AJAX轮询原理是设置定时器,定时通过AJAX同步服务器数据.这种方式存在延时且对服务端造成很大负载.直到2011年,IETF才标准化WebSocket--一种基于TCP套接字进行收发数据的协议.现如今主流浏览器均已支持WebSocket. socket.io将数据传输部分独立出来形成了en

  • 网管必读,网管系统建设的思维转变

    过去几年中,企业IT部门主管肩负的责任发生了显著的变化:一方面公司网络的规模和复杂性成倍增长,越来越多的新业务被移植到网络环境中来运行;另一方面公司内各业务部门以及外部客户也越来越依赖于网络来完成日常的业务处理和通信,任何网络或服务中断甚至性能下降都会对企业业务造成严重影响.同时为适应市场经济的严酷竞争,控制IT投资和运营成本也成为了IT部门主管需要考虑的课题. 为确保企业业务的正常运行,国内几乎所有大中型企业的领导都已经认识到建设网络管理系统的重要性,并且多数企业已经根据各自当前的管理需求投资

  • C语言编程数据结构线性表之顺序表和链表原理分析

    目录 线性表的定义和特点 线性结构的特点 线性表 顺序存储 顺序表的元素类型定义 顺序表的增删查改 初始化顺序表 扩容顺序表 尾插法增加元素 头插法 任意位置删除 任意位置添加 线性表的链式存储 数据域与指针域 初始化链表 尾插法增加链表结点 头插法添加链表结点 打印链表 任意位置的删除 双向链表 测试双向链表(主函数) 初始化双向链表 头插法插入元素 尾插法插入元素 尾删法删除结点 头删法删除结点 doubly-Linked list.c文件 doubly-Linkedlist.h 线性表的定

  • 老生常谈C语言链表小结

    目录 链表的概念及结构 概念 结构 链表的分类 单链表的实现(无头) 双向链表的实现 总结:链表和顺序表的区别 链表的概念及结构 概念 链表是一种物理存储结构上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的 . 结构 代码 struct Slist { int* a; struct Slist* next; }; 逻辑结构: 物理结构: 注意: 从上图可以看出,链式结构在逻辑上是连续的,但是在物理上是不一定是连续的. 这些结点一般是从堆上申请出来的. 从堆上申请的空

  • C++超详细讲解单链表的实现

    目录 单链表的实现(从入门到熟练) 概念和结构 链表的实现 增删查改接口 节点结构体创建 节点开辟 数据打印 链表尾插数据 头删 链表数据查找 链表pos位置前插数据 链表pos位置后插数据 链表pos位置数据删除 链表节点释放 链表与顺序表区别 链表的优缺点 顺序表的优缺点 单链表的实现(从入门到熟练) 概念和结构 概念:链表是一种物理存储结构上非连续.非顺序的存储结构 数据元素的逻辑顺序是通过链表中的指针链 接次序实现的 图示: 注意: 链表结构在逻辑上为连续的,但是物理上(内存中)不一定连

  • C++实现STL迭代器萃取的示例代码

    目录 导言 什么是迭代器 为什么需要迭代器萃取 value type difference type reference type point type iterator_category 知识点补充 例外 导言 什么是迭代器 迭代器是一种抽象的设计概念,<Design Patterns>一书中对于 iterator 模式的定义如下:提供一种方法,使之能够依序巡访某个聚合物(容器)所含的各个元素,而又无需暴露该聚合物的内部表述方式. 为什么需要迭代器萃取 有时在我们使用迭代器的时候,很可能会用

随机推荐