์น mvcํจํด์ ํ์ฉํด view์์ ์ฑ๊ณต์ ์ผ๋ก ๋ฐํ๋ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ๊ฐ์ง๊ณ ์์ ๋ค๋ฅธview์ ๋ฟ๋ ค์ค ์ ์๋์??
// ๋ฌ๋ ฅ์ ์ด๋ฒคํธ ํด๋ฆญ์ ํด๋น์ผ์ ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋๋ก ๊ฐ์ ธ์ ์์ (์ด๊ฑด ๋ฐ์ดํฐ ํ๋์ฉ ๋ฐ์์ผํด์ list์ฐ๋ฉด์๋จ) public WorkHistoryDTO CalenderDay(String inputDate, String token) { String apiAddress = serverAddress + "/api/Job/WorkHistory-Day?inpuDate=" + inputDate; return getDayData(apiAddress, token); } // ์ผ๊ฐ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ private WorkHistoryDTO getDayData(String apiAddress, String token) { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + token); HttpEntity entity = new HttpEntity(headers); try { // ์๋ฒ๋ก GET ์์ฒญ์ ๋ณด๋ด๊ณ ์๋ต์ ๋ฐ์ ResponseEntity response = restTemplate.exchange( apiAddress, HttpMethod.GET, entity, WorkHistoryDTO.class ); WorkHistoryDTO workHistory = response.getBody(); // workHistory๊ฐ null์ด ์๋์ง ํ์ธ if (workHistory != null) { // ๊ฒฐ๊ณผ ๋ฐํ System.out.println("๋ถ๋ฌ์จ ๋ฐ์ดํฐ: " + workHistory); return workHistory; } else { System.out.println("๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค."); return null; } } catch (RestClientResponseException ex) { if (ex.getRawStatusCode() == 401) { System.err.println("๋ก๊ทธ์ธ ์คํจ ๋ฉ์์ง: " + ex.getResponseBodyAsString()); } else { System.err.println("์๋น์ค ์ค๋ฅ: " + ex.getResponseBodyAsString()); } return null; } } //๋ฌ๋ ฅ ์ด๋ฒคํธ ํด๋ฆญ์ ๋ง๋๋ ์ง ๋ฐ์ดํฐ ๋๊ธฐ๊ธฐ @GetMapping("/dataclick") public ResponseEntity getDay(@RequestParam(name = "inpuDate") String inputDate, @RequestHeader("Authorization") String authorizationHeader) { String token = authorizationHeader.replace("Bearer ", ""); try { WorkHistoryDTO result = service.CalenderDay(inputDate, token); if (result != null) { // ๋ฐ์ดํฐ๊ฐ ์๋ ๊ฒฝ์ฐ JSON ์๋ต ๋ฐํ return new ResponseEntity(result, HttpStatus.OK); } else { // ๋ฐ์ดํฐ๊ฐ ์๋ ๊ฒฝ์ฐ No Content ์ํ์ฝ๋ ๋ฐํ return new ResponseEntity(HttpStatus.NO_CONTENT); } } catch (Exception e) { // ์์ธ ์ฒ๋ฆฌ ๋ก์ง์ ์ถ๊ฐํ์ฌ ์ ์ ํ ์๋ต์ด๋ ๋ก๊น
์ ์ํํ ์ ์์ต๋๋ค. e.printStackTrace(); // ์์ธ๋ฅผ ์ฝ์์ ์ถ๋ ฅํ๊ฑฐ๋ ๋ก๊น
ํ ์ ์์ต๋๋ค. // ์๋ฒ ์ค๋ฅ์ธ ๊ฒฝ์ฐ Internal Server Error ์ํ์ฝ๋ ๋ฐํ return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } }// API ํธ์ถ $.ajax({ url: `/dataclick?inpuDate=${targetDate}`, method: 'GET', headers: { 'Accept': 'application/json', 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, success: function (data) { console.log('๋ฐ์ ๋ฐ์ดํฐ:', JSON.stringify(data)); // editPage๋ก ์ด๋ window.location.href = '/editPage'; }, error: function (error) { console.error('๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ ์คํจ:', error); }์ฑ๊ณต์ ์ผ๋ก ๋ด๊ฐ ํด๋ฆญํ ๋ ์ง์ ๋ฐ์ดํฐ๋ ์๋ฐ์์ค๊ณ ๊ทธ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ editPage์์ ํ์ด์ง์ ๊ฐ์ ธ์จ๋ฐ์ดํฐ๋ฅผ ๋ฟ๋ฆฌ๊ณ ์ถ์ต๋๋ค