Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 响应中的弹簧复位错误格式_Java_Spring_Spring Boot - Fatal编程技术网

Java 响应中的弹簧复位错误格式

Java 响应中的弹簧复位错误格式,java,spring,spring-boot,Java,Spring,Spring Boot,我尝试使用ResponseEntity返回byte[]对象 return new ResponseEntity<>(new Response(ResultCode.SUCCESS, SUCCESS).setResult(dataObj), HttpStatus.OK); 回答是这样的: 为什么我们有不同的选择?我能用第二张图像这样的数据返回响应吗?试试下面的代码。它将在访问此API时发送映像本身作为响应 @GetMapping(value = "/image/{id}&

我尝试使用ResponseEntity返回byte[]对象

return new ResponseEntity<>(new Response(ResultCode.SUCCESS, SUCCESS).setResult(dataObj), HttpStatus.OK);
回答是这样的:


为什么我们有不同的选择?我能用第二张图像这样的数据返回响应吗?

试试下面的代码。它将在访问此API时发送映像本身作为响应

@GetMapping(value = "/image/{id}")
public ResponseEntity<?> getImageById(@PathParam Long id) throws Exception {
  String imageData = this.entityRepository.findById(id).orElse(null).getData();
  byte[] imageByte = Base64.getDecoder().decode(new String(imageData).getBytes("UTF-8"));
  MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(mediaType);
  return new ResponseEntity<>(imageByte, headers, HttpStatus.OK);
}
@GetMapping(value=“/image/{id}”)
公共响应性getImageById(@PathParam Long id)引发异常{
String imageData=this.entityRepository.findById(id).orElse(null).getData();
byte[]imageByte=Base64.getDecoder().decode(新字符串(imageData.getBytes(“UTF-8”));
MediaType MediaType=MediaType.APPLICATION\u OCTET\u STREAM;
HttpHeaders=新的HttpHeaders();
headers.setContentType(mediaType);
返回新的ResponseEntity(imageByte、headers、HttpStatus.OK);
}
@GetMapping(value = "/image/{id}")
public ResponseEntity<?> getImageById(@PathParam Long id) throws Exception {
  String imageData = this.entityRepository.findById(id).orElse(null).getData();
  byte[] imageByte = Base64.getDecoder().decode(new String(imageData).getBytes("UTF-8"));
  MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(mediaType);
  return new ResponseEntity<>(imageByte, headers, HttpStatus.OK);
}