fix: 전자고지연계파일업로드 예제 fix

dev
gitea-관리자 1 year ago
parent d74a3bc621
commit 58b158fe37

@ -42,7 +42,7 @@ public class CmmEnsFileController {
* @param fileReq * @param fileReq
* @return * @return
*/ */
@Operation(summary = "시설관리공단 전자고지 대상 엑셀업로드 처리", description = "시설관리공단 전자고지 대상 엑셀업로드 처리") @Operation(summary = "시설관리공단 전자고지 대상 엑셀업로드 처리", description = "시설관리공단 전자고지 대상 엑셀업로드 처리<br><a href='http://localhost:8082/fmcExcelUpload.html'>전자고지연계파일처리</a>")
@PostMapping(value = "/fmcExcelUpload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/fmcExcelUpload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseDTO<?> fmcExcelUpload(@ModelAttribute FmcExcelUpload fileReq) { public ApiResponseDTO<?> fmcExcelUpload(@ModelAttribute FmcExcelUpload fileReq) {
service.fmcExcelUpload(fileReq); service.fmcExcelUpload(fileReq);

@ -5,9 +5,7 @@
<title>excel upload</title> <title>excel upload</title>
</head> </head>
<body> <body>
<form>
<form action="http://localhost:8081/api/cmm/fmcExcelUpload" method="post"
enctype="multipart/form-data">
<fieldset> <fieldset>
<legend>선택</legend> <legend>선택</legend>
<label for="sysSeCode">시스템구분</label> <label for="sysSeCode">시스템구분</label>
@ -23,46 +21,53 @@
</select><br/> </select><br/>
<label>전송일</label> <label>전송일</label>
<input type="date" id="sndngDt" required/><br/> <input type="date" id="sndngDt" required/><br/>
<input type="file" accept="application/vnd.ms-excel" id="files" name="files" required/> <input type="file"
accept="application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
id="files" name="files" required/>
</fieldset> </fieldset>
<button>upload</button> <button type="button" onclick="handleSubmit()">upload</button>
</form>
</form>
<script>
const handleSubmit = async (event) => {
event.preventDefault();
const form = event.currentTarget;
<script type="text/javascript" src="http://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
function handleSubmit() {
const form = document.querySelector("form");
let sndngDt = document.querySelector("#sndngDt").value.replaceAll("-", "")
let file = document.querySelector("#files").files[0];
if(!sndngDt){
alert('전송일을 선택하세요');
return false;
}
if(!file){
alert('업로드할 파일을 선택하세요');
return false;
}
const fd = new FormData(); const fd = new FormData();
fd.append('sysSeCode', document.querySelector("#sysSeCode").value); fd.append('sysSeCode', document.querySelector("#sysSeCode").value);
fd.append('sndngSeCode', document.querySelector("#sndngSeCode").value); fd.append('sndngSeCode', document.querySelector("#sndngSeCode").value);
fd.append('sndngDt', document.querySelector("#sndngDt").value.replaceAll("-", "")); fd.append('sndngDt', document.querySelector("#sndngDt").value.replaceAll("-", ""));
fd.append('files', document.querySelector("#files").files[0]); fd.append('files', document.querySelector("#files").files[0]);
const url = form.action; $.ajax({
url: 'http://localhost:8081/api/biz/cmm/fmcExcelUpload',
const res = await fetch(url, data: fd,
{method: 'post', body: fd} cache: false,
); contentType: false,
processData: false,
try { enctype : 'multipart/form-data',
const data = await res.json(); type: 'POST',
success: function(data) {
console.log(data); console.log(data);
alert(JSON.stringify(data.data)) alert(JSON.stringify(data));
alert(JSON.stringify(data)) },
} catch (e) { error: function(e) {
console.log(res) console.log(e);
alert(JSON.stringify(e));
} }
});
} }
const form = document.querySelector('form'); </script>
form.addEventListener('submit', handleSubmit);
</script>
</body> </body>
</html> </html>

Loading…
Cancel
Save