대용량 파일을 청크로 읽고 JSON으로 변환하여 Spring MVC 컨트롤러에 전송하는 코드가 있습니다. 내 메소드는 다음과 유사합니다. 원하는 위치로 전달합니다. noBytes에서 오프셋과 chunksize 영역에서 시작, 결과는 전달은 JSON로 변환하고파일 청크를 Java 페이지로 변환
public String readByteBlock(File file, int offset, int noBytes) throws IOException {
InputStream in = new FileInputStream(file);
byte[] result = new byte[noBytes];
in.skip(offset);
in.read(result, 0, noBytes);
return FileSaver.byteArrayToString(result, noBytes);
}
내가 내 컨트롤러에 다음 및 이전 페이지 매김 작업을하는 데 문제가 내 컨트롤러에 요청하실 수 있습니다
@RequestMapping("/page/{id}")
@ResponseBody
File file = new File("C:/teste.txt");
FileSaver fs = new FileSaver();
int byteblock = 100;
int offset = 0;
if(id.equals("next")){
offset = (int) req.getSession().getAttribute("prevEndPos");
String s = fs.readByteBlock(file, offset, byteblock);
req.getSession().setAttribute("prevStartPos", offset);
req.getSession().setAttribute("prevEndPos", (offset + byteblock));
return s;
}
if(id.equals("prev")){
offset = (int) req.getSession().getAttribute("prevStartPos") - byteblock ;
if(offset < 0){
String s = fs.readByteBlock(file, 0, byteblock);
return s;
}
String s = fs.readByteBlock(file, offset, byteblock);
req.getSession().setAttribute("prevStartPos", (offset - byteblock));
return s;
}
String s = fs.readByteBlock(file, 0, byteblock);
req.getSession().setAttribute("prevStartPos", offset);
req.getSession().setAttribute("prevEndPos", (offset + byteblock));
return s;
그래서 파일의 각 청크는 m의 html 테이블에 저장됩니다 y 응용 프로그램, 내 세션에 현재 블록 startByte 및 endByte 저장 한 사용자가 내 페이지에서 이전 단추를 누르면 어떻게 이전 블록을 시작하고 끝났는지 알 수 있습니까? 세션은 현재 페이지가 아닌 이전 페이지를 보유하기 때문에