java - REST Web 服务返回基础 SQL 查询中不存在的字段

标签 java mysql rest jersey

当我尝试访问以下 REST 服务时,它返回所有数据以及“SupplierPayment”实体类“customerId”中不存在的字段。

@GET
@Produces(MediaType.APPLICATION_JSON)
public List<SupplierPayment> getAllSupplierPaymentsService() {
    return (ArrayList<SupplierPayment>) supplierPaymentDao.getAllSupplierPayments();
}

这是 getAllSupplierPayments() 方法:

public List<SupplierPayment> getAllSupplierPayments() {
    String query = "SELECT * FROM supplierpayment";
    return (ArrayList<SupplierPayment>) getJdbcTemplate().query(query,
            new BeanPropertyRowMapper<SupplierPayment>(SupplierPayment.class));
}

以下是“SupplierPayment”类中的所有字段:

private Integer supplierPaymentId;
private BigDecimal amount;
private Integer purchaseInvoiceId;
private Integer supplierId;
private Integer paymentMethodId;
private String description;
private Integer checkId;
private Integer fromBankAccountId;
private Integer toBankAccountId;
private String creditCardNo;
private Timestamp created;
private Integer createdBy;

当我调试时,我发现Web服务的ArrayList没有返回该字段,然后不知何故我在响应中找到了该字段。

我尝试截断并删除表格并逐个添加列。我发现只有当我将“supplierId”列添加到表中并且其值与“supplierId”相同时,该字段才会在响应中返回。我认为“customerId”列以前就存在,但我删除了它。

最佳答案

由于表中先前存在列,我发现SupplierPayment实体类中存在以下getter和setter:

public Integer getCustomerId() {
    return supplierId;
}

public void setCustomerId(Integer customerId) {
    this.supplierId = customerId;
}

删除它们后,问题就解决了。

关于java - REST Web 服务返回基础 SQL 查询中不存在的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938654/

相关文章:

java - QueryDSL:QueryDSL 2.9.0 中 ConstructorExpression 和 CaseBuilder 的 JPA 示例

java - 如何找到星期几 - Java

java - 如何在 jax-rs Restful web 服务中获取 Json 对象

c# - ServiceStack - 将 HttpStatus 返回到 Android 设备

java - 尝试将数据从一个 fragment 传递到另一个 fragment ,但数据未出现

java - 线程中的异常 "main"java.util.Input MismatchException

MySQL 将差异值插入到两个表中

mysql - 在 phpMyAdmin 上工作的原始 Mysql 查询在 laravel 中返​​回错误

MySQL 触发器 - 如果超出范围,则不接受记录更新

Java HttpGet,服务中打开文件过多错误