首页 > 解决方案 > Spring Boot,数组,JPA,数据库,角度

问题描述

是否可以使用 4 个元素的数组,例如 (int a=5; int b=6; int c=7; int d=8 ) 和 int []arr= {a,b,c,d} 并将它们放入具有不同列的表,例如:

column a                    column b              column c         column d

   5                           6                    7                8

有人可以给我一个示例课程或给我一个相同问题的链接:

@Table(name = "columns")
int[]arr = {a,b,c,d}
@Column(name="a") 

.......在此处输入代码。如何在此处使用带有元素的列。我不知道

就像是:

package com.example.demo.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="infect")
public class Infect {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;
    @Column(name= "coordinatex")
    private int coordinatex;
    @Column(name= "coordinatey")
    private int coordinatey;
    @Column(name= "firstx")
    private int firstx;
    @Column(name= "firsty")
    private int firsty;
    
    
    public Infect(int coordinatex, int coordinatey, int firstx, int firsty) {
        super();
        this.coordinatex = coordinatex;
        this.coordinatey = coordinatey;
        this.firstx = firstx;
        this.firsty = firsty;
    }
    
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public int getCoordinatex() {
        return coordinatex;
    }
    public void setCoordinatex(int coordinatex) {
        this.coordinatex = coordinatex;
    }
    public int getCoordinatey() {
        return coordinatey;
    }
    public void setCoordinatey(int coordinatey) {
        this.coordinatey = coordinatey;
    }
    public int getFirstx() {
        return firstx;
    }
    public void setFirstx(int firstx) {
        this.firstx = firstx;
    }
    public int getFirsty() {
        return firsty;
    }
    public void setFirsty(int firsty) {
        this.firsty = firsty;
    }
}

就像如何在 arr[coordinatex,coordinatey,firstx,firsty] 中制作这个坐标,坐标,firstx,firsty,并将它们放在不像私有 int 坐标的列中,我希望它们在数组中然后在列中

标签: arraysspring-bootjpaspring-data-jpa

解决方案


而不是这个

@Table(name = "columns")
int[]arr = {a,b,c,d}
@Column(name="a") 

用这个

@Table(name = "columns")
public class Yourclass {
   @Column(name="a") 
   public int a;

   @Column(name="b") 
   public int b;

   @Column(name="c") 
   public int c;

   @Column(name="d") 
   public int d;
}

推荐阅读