본문 바로가기
728x90

springboot40

[Spring] @PutMapping, @DeleteMapping 403 Forbidden 에러 윈도우 환경인 로컬에서는 잘되던 @DeleteMapping이 리눅스 환경에 배포 후 안된다. - 환경설정 문제인거 같아서 관련 내용으로 구글링 - SecurityConfig에 아래 내용을 추가해봤지만 효과가 없었다. .antMatchers(HttpMethod.DELETE,"/**") - WebConfig를 수정하니 효과가 있었다. @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping(("/**")) .allowedOrigins("*") .allowedMethods( HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name(), HttpMethod... 2022. 6. 28.
[Javascript] 웹으로 PDF 띄우기 회사 요구사항으로 PDF를 뛰워야했다. - 이전에 Java로 띄웠었는데, 간편하게 Javascript로 가능하다. window.open('서버파일경로+파일명.확장자'); - Java로 하면 FileInputStream fis = null; BufferedOutputStream bos = null; try { String pdfFileName = "경로+파일명.확장자"; File pdfFile = new File(pdfFileName); // 클라이언트 브라우져에서 바로 보는 방법(헤더 변경) response.setContentType("application/pdf"); // 이 구문이 있으면 [다운로드], 이 구문이 없다면 바로 target 지정된 곳에서 띄울 수 있다. //response.addHead.. 2022. 6. 27.
[Spring] 파일 업로드 시 파일명 변경하기 파일 업로드 시 파일명 변경이 필요함 - 개발하는데, 파일명을 강제로 바꿔줘야 하는 일이 발생했다. - Javascript의 input:file에서는 변경이 불가능하다. - Java에서 파일을 받아 파일명을 변경했다. @PostMapping("/save") @ResponseBody public long save(@RequestParam("imgCoverFile") MultipartFile file) { File targetFile = new File("/path/path2/" + newFileName); InputStream fileStream = file.getInputStream(); FileUtils.copyInputStreamToFile(fileStream, targetFile); } - Apac.. 2022. 6. 27.
[Spring] @PutMapping, @DeleteMapping 사용하기 RestAPI규칙을 지켜보고자 @DeleteMapping을 사용해보았다. - 화면에서는 405에러가 나고, 서버쪽을 봤더니 Request method 'DELETE' not supported 가 찍혀있었다. 구글링 결과 SpringBoot 2.2 이상 버전에서는 설정을 따로 해줘야한다고 한다. - yml파일에 아래코드를 작성했다. spring: mvc: hiddenmethod: filter: enabled: true 재시작 후 작성한 API가 정상 작동하는 것을 확인할 수 있다. 추가 - Ajax로 요청 시 Delete, Get, Put은 body에 파라미터가 들어가지 않으므로, URL에 추가해줌으로써 파라미터를 서버쪽으로 넘겨줘야 한다. const url = "/xxx/yyy/" + String(dat.. 2022. 6. 27.
728x90