relacionado:
ejemplo para leer uun registro postgres:
package com.ejemplo.demo.service;
import com.ejemplo.demo.entity.Usuario;
import com.ejemplo.demo.repository.UsuarioRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UsuarioService {
@Autowired
private UsuarioRepository usuarioRepository;
@GetMapping("/givemeone")
public ResponseEntity<String> giveMeOne() throws Exception {
CredentialsLogin dto = new CredentialsLogin();
dto.setPassword("abc");
String jsonResponse = toJsonString(dto);
return ResponseEntity.ok( jsonResponse );
}
private String toJsonString(Object dto) throws Exception {
String jsonResponse = objectMapper.writeValueAsString(dto);
return jsonResponse;
}
}