Nerdvan
0
Q:

show image with sprinboot

@GetMapping("database/{id}")
public ResponseEntity<byte[]> fromDatabaseAsResEntity(@PathVariable("id") Integer id) 
        throws SQLException {

	Optional<PrimeMinisterOfIndia> primeMinisterOfIndia = imageRepository.findById(id);
	byte[] imageBytes = null;
	if (primeMinisterOfIndia.isPresent()) {
	
		imageBytes = primeMinisterOfIndia.get().getPhoto().getBytes(1,
					(int) primeMinisterOfIndia.get().getPhoto().length());
	}
	
	return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(imageBytes);
}
0

New to Communities?

Join the community