为什么我在 spring boot/posgresql 中看不到映射实体的表和序列 id?

问题描述 投票:0回答:1

作为一名新的 Spring 开发人员,我正在尝试将实体与数据库映射

但是,我看不到“客户表”和“序列”id

客户课堂

@Entity
@Table(name = "customer")
public class Customer{
@Id
@SequenceGenerator(
        name = "customer_id_sequence",
        sequenceName = "customer_id_sequence"
)
@GeneratedValue(
        strategy = GenerationType.SEQUENCE,
        generator = "customer_id_sequence"
)
private  Integer id;
private String name;
private String email;
private Integer age;
public Customer(){

}

客户服务

@Service
public class CustomerService {

private final CustomerDao customerDao;

public CustomerService(CustomerDao customerDao) {
    
    this.customerDao = customerDao;
}

public List<Customer> getAllCustomers(){

    return customerDao.selectAllCustomers();
}

public Customer getCustomer(Integer id){

    return customerDao.selectCustomersById(id)
            .orElseThrow(()->new ResourceNotFound(("customer with id [%s] not found".formatted(id))));
}

}

客户控制器

@RestController
public class CustomerController {
private final CustomerService customerService;

public CustomerController(CustomerService customerService) {

    this.customerService = customerService;
}

@GetMapping("/api/v1/customers")
public List< Customer> getCustomers(){
    return customerService.getAllCustomers();
}

@GetMapping("/api/v1/customers/{customerId}")
public Customer getCustomer(@PathVariable("customerId")Integer customerId){

    return customerService.getCustomer(customerId);
}

}

@Repository

public class CustomerDataAccessService implements CustomerDao{

//数据库 私人最终静态列表客户;

Postgres

postgres 数据库

问题:

在此输入图片描述

关于属性


jpa:
   hibernate:
     ddl-auto: create-drop

   properties:
    hibernate:
      dialect: org.hibernate.dialect.PostgreSQLDialect
      format_sql: true
    show_sql: false

spring postgresql spring-data-jpa
1个回答
0
投票

您需要在实体类中拥有 getter setter 才能访问您的私有字段。数据库中应该仍然显示一个空表。 如果您可以分享 hibernate 运行的 sql 查询的日志,它会提供更清晰的图片

© www.soinside.com 2019 - 2024. All rights reserved.