Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
¿Por qué obtener solo valores en lugar de claves y valores en la respuesta JSON?

Estoy tratando de recuperar datos de la base de datos utilizando una consulta nativa de SQL, pero solo obtengo valores en lugar de claves y valores en la respuesta JSON. ¿Cómo puedo recuperar datos con clave y valor en la respuesta Json?

Entidad:

 @Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor @Table(name = "Products") public class ProductModel { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id private Long id; @Column(name = "Category") private String category; @Column(name = "ProductName") @Lob private String productName; @Column(name = "Price") private int price; @Column(name = "Slider") private Boolean slider; @Column(name = "SpecialOffer") private Boolean specialOffer; @Column(name = "NewPrice") private int newPrice; @Column(name = "FullDescription") @Lob private String fullDescription; @Column(name = "Image") @Lob private String image; }

Repositorio:

 @Repository public interface ProductRepository extends JpaRepository<ProductModel, Long> { @Query(value = "select id,image,product_name,price,new_price from products where slider is true", nativeQuery = true) List<String> getSliderContent(); }

Servicio

 @Service public class ProductService { @Autowired private ProductRepository productRepository; public List<String> getSliderContent(){ List<String> lstMovie = new ArrayList<>(); lstMovie = productRepository.getSliderContent(); return lstMovie; } }

Controlador:

 @CrossOrigin("*") @RestController @RequestMapping("/products") public class ProductController { @Autowired private ProductService productService; @GetMapping("/sl") public List<String> getSliderContent(){ List<String> ls = productService.getSliderContent(); return ls; } }

Tengo datos como json

 ["1, https://cdn.x-kom.pl/i/setup/images/prod/big/product-new-big, , 2021/10/pr_2021_10_8_14_22_27_699_08.jpg, Acer Swift 3 i5-1135G7/16GB/512/W11 Srebrny Intel Evo, 4800, 4500"]

Datos esperados en este formato:

 ["id: 1, image: 'https://cdn.x-kom.pl/i/setup/images/prod/big/product-new-big, ,2021/10/pr_2021_10_8_14_22_27_699_08.jpg', product name: 'Acer Swift 3 i5-1135G7/16GB/512/W11 Srebrny Intel Evo', price: 4800, new_price: 4500"]

¿Alguien puede explicar cómo hacerlo? Devuelvo datos como String , eso es un problema, pero ¿cómo puedo devolver el objeto Json con una consulta nativa?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!