繁体   English   中英

如果我正在编写只有特定列的本机查询,如何使用 Jpa 在 postman 中显示列名

[英]How I can show column name in postman using Jpa if I am writing native query having only specific columns

  • 我在我的存储库中进行了本机查询,它只给出特定的列 output。

    @Query(value = "SELECT installation_id,description,checklist_steps,creation_date,location,status FROM installation_details", nativeQuery = true) List < Object > findCustomInstallation();

  • 但是我在 postman 上得到的响应只向我显示列内的数据,那么我如何也可以显示列名?

  • Note:- I am not using my model as it is having one to one mapping of other table also and if I run query using my model it is also showing me data of other table on postman that is why I used Object instead of model.

  • 我得到的回应是这样的

> { > "status": 1, > "message": "Successfully Fetched", > "myObjectList": [ > [ > 1, > "traffic project", > "13", > "2021-01-30T06:57:34.000+0000", > "Delhi", > 1 > ],

您可以使用预测来完成这项工作。

创建一个只有 getter 的接口

public interface InstallationDetailsProjection 
{
    Long getInstallation_id();
    String getDescription();
//similar for other fields
}

然后将别名添加到您的本机查询

@Query(value = "SELECT installation_id as installation_id,description as description //more fields
 FROM installation_details", nativeQuery = true) List < InstallationDetailsProjection > findCustomInstallation();

这应该可以解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM