@RequestMapping(value = "/all", method = RequestMethod.GET)
public ResponseEntity<List<ItemVO>> listAll() {
ResponseEntity<List<ItemVO>> entity = null;
try {
List<ItemVO> list=service.listAll();
for(ItemVO i : list){
InputStream in = getClass().getClassLoader().getResourceAsStream(i.getFilepath_img());
i.setByte_img(IOUtils.toByteArray(in));
}
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_PNG);
entity = new ResponseEntity<List<ItemVO>>(list, HttpStatus.OK);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
entity = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return entity;
}
이미지가 SRC/메인/웹 애플리케이션/자원/IMG 폴더에있는같이 getResourceAsStream 반환 NullpointException (spring4)
public class ItemVO{
private int item_id;
private String filepath_img;
private byte[] byte_img;
}
VO,
저장된 파일 경로 같다 "/ IMG/XXX
자바 : .PNG "
내가 스택 추적을 할 수 무슨 생각이 없다 .lang.NullPointerException
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2146)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:2102)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2123)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:2078)
at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:721)
'i.getFilepath_img()'경로를 확인 했습니까? –
네, 잘 작동 했습니까? – hsyou
목적을 확인하기 위해이 경로로 시도하십시오. main/webapp/resources/img/xxx.png' –