import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@RestController
@RequestMapping("/test")
public class DemoController{
@GetMapping("/image")
public ResponseEntity<byte[]> getImage() throws IOException {
File file = new File("C:\\Users\\win10-pc\\Desktop\\1.png");
byte[] bytes = Files.readAllBytes(file.toPath());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_PNG);
return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
}
}