前端
<!DOCTYPE html>
<html lang="en" class="no-js" xmlns:th="http://www.thymeleaf.org">
<body id="body" data-spy="scroll" data-target=".header">
<!--<div th:replace="theme/left-music::left-music"></div>-->
<!-- Products -->
<div>
<input id="name" />
<input type="file" id="file" />
<button id="btnShow" class="button">提交</button>
</div>
<script th:src="@{/diy/vendor/jquery.min.js}" type="text/javascript"></script>
<script>
$(function () {
$("#btnShow").on('click', function () {
debugger
var formdata = new FormData();
formdata.append("name", $("#name").val());
formdata.append("file", $("#file")[0].files[0]);
$.ajax({
type: 'POST',//方法类型
url: "/test/upload",
data: formdata,
cache: false,
processData: false,
contentType: false,
success: function (result) {
console.log(result);
},
error: function () {
swal("操作失败", {
icon: "error",
});
}
});
});
})
</script>
</body>
<!-- END BODY -->
</html>
后端正常的获取数据即可