나는 REST API가 있고 csv 파일에서 TreeMap을 만드는 메서드를 호출하고 각 API 호출의 나머지 부분에 대해 TreeMap을 사용하려고합니다. 메소드를 호출하여 TreeMap을 설정하고 나머지 API 호출에 대해 TreeMap을 사용하려고합니다. 그래서 아래컨트롤러에서 한 번만 calla 메서드하는 방법
TreeMap의 작성을위한 나의 방법은
public void createTreeMap(){
CSVReader reader = new CSVReader(new FileReader("C:\\Users\\result.csv"), ',' , '"' , 1);
TreeMap <Integer,ArrayList<Long>> result=new TreeMap <Integer,ArrayList<Long>>();
//Read CSV line by line and use the string array as you want
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine != null) {
//Verifying the read data here
ArrayList<Long> result_01 = new ArrayList<Long>();
for(int k=0;k<nextLine[1].replace("[", "").replace("]", "").replace(" ", "").split(",").length;k++){
result_01.add(Long.parseLong(nextLine[1].replace("[", "").replace("]", "").replace(" ", "").split(",")[k]));
}
result.put(Integer.parseInt(nextLine[0]), result_01);
}
}
}
내가 나무는 API가 내가 대신 called.but 때마다지도를 만들 수 있습니다
@RestController
public class HomeController {
@RequestMapping(value="/api/sid",produces={MediaType.APPLICATION_JSON_VALUE},method=RequestMethod.GET)
public ResponseEntity<Map<String, List<Model>>> getid(@RequestParam("sid") int sid) {
Map<String, List<Model>> Map = new HashMap<String, Object>();
List<Model> model=new List<Model>();
model=get_model();
Map.put("hi",model)
return new ResponseEntity<Map<String, List<Model>>>(Map,HttpStatus.OK);
}
@ResponseBody
public List<Model> get_model(){
List list =new List<Model>();
//here I have to use the treemap
return list;
}
}
나머지 API를 컨트롤러에게 있습니다 한 번만 생성하고 응답 본문 get_model 메소드에 액세스해야합니다. 모든 도움을 주시면 감사하겠습니다.
캐시 사용은 어떻게됩니까? –
어디에서 캐시를 정의해야합니까? – RKR
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html –