首页 > 解决方案 > 在 Spring Boot 实体类中使用 desc 作为字段名

问题描述

尽管遵循了正确的过程模型,但没有为以下模型创建表

  @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @Entity
    public class Product {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        Integer pid;
    
        String name;
        String desc;
        double price;
    }

在此处输入图像描述

标签: sqlspring-bootjpa

解决方案


所以我为 JPA 创建了一个实体类,其中有一个字段名称 desc。我使用的是 MySQL 数据库。但由于某种原因,我收到以下错误。 该模型

@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Integer pid;

    String name;
    String desc;
    double price;
}

在此处输入图像描述

后来我更改了字段名称,整个事情都在工作。ORM 会自动创建表。 有效的更新模型

@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Integer pid;

    String name;
    String description;
    double price;
}

推荐阅读