@Column可以解决数据库字段为关键字问题

Posted zxq-study-java

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了@Column可以解决数据库字段为关键字问题相关的知识,希望对你有一定的参考价值。

在下面代码中numeric字段是数据库中的数值类型的关键字,只有加上@Column之后才不会报错

import javax.persistence.*;

@Table(name = "tb_spec_param")
public class SpecParam {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long cid;
private Long groupId;
private String name;
@Column(name = "`numeric`")
private Boolean numeric;
private String unit;
private Boolean generic;
private Boolean searching;
private String segments;

// getter和setter ...

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getCid() {
return cid;
}

public void setCid(Long cid) {
this.cid = cid;
}

public Long getGroupId() {
return groupId;
}

public void setGroupId(Long groupId) {
this.groupId = groupId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Boolean getNumeric() {
return numeric;
}

public void setNumeric(Boolean numeric) {
this.numeric = numeric;
}

public String getUnit() {
return unit;
}

public void setUnit(String unit) {
this.unit = unit;
}

public Boolean getGeneric() {
return generic;
}

public void setGeneric(Boolean generic) {
this.generic = generic;
}

public Boolean getSearching() {
return searching;
}

public void setSearching(Boolean searching) {
this.searching = searching;
}

public String getSegments() {
return segments;
}

public void setSegments(String segments) {
this.segments = segments;
}
}




























































































以上是关于@Column可以解决数据库字段为关键字问题的主要内容,如果未能解决你的问题,请参考以下文章

Incorrect column name 问题解决

mysql数据库表字段使用DESC等关键字报错及解决方法

Hibernate -- @Column.unique 用于非关键字段

oracle的column格式化导致字段值显示为"####"的处理办法

thinkphp5.0 column多字段问题

mybatis和mybatisPlus中解决实体类字段与数据库关键字冲突问题