Spring Boot JPA 选择特定列的结果应为 JSON 格式
@Query(value = "SELECT id, property_id, display_name FROM property_basic_property_details WHERE status='1' and unique_id=:unique_id", nativeQuery = true) public List propertydisplayname(String unique_id);
@GetMapping("/propertydisplayname/{unique_id}")
public List<PropertyBasicPropertyDetails> propertydisplayname(@PathVariable String unique_id){
List<PropertyBasicPropertyDetails> PropertyBasicPropertyDetails1= propertyBasicPropertyDetailsRespository.propertydisplayname(unique_id);
return PropertyBasicPropertyDetails1;
}
错误:
无法执行查询; SQL [SELECT id, property_id, display_name FROM property_basic_property_details WHERE status='1' and unique_id=?]
输出:
{ { "id":1, "property_id":pp_001, "display_name":test1, }, { "id":2, "property_id":pp_002, "display_name":test2, }, }