这个功能是在点击名称弹出窗口显示详细信息,但是要在这个窗口中添加一个可以上传文件的功能。如果我的方法错了想请教大佬们怎么才能实现这个功能????
HtKnowledgeFileInfo是用来存储文件的
controller层
@PostMapping("/uploadFile")
@ResponseBody
public AjaxResult uploadFile(@RequestParam(value="file", required=false) MultipartFile file) throws IOException
{
String filePath = Global.getUploadPath();
String nameType=file.getOriginalFilename();
String Name=nameType.substring(0,nameType.lastIndexOf("."));
HtKnowledgeFileInfo fileInfo=new HtKnowledgeFileInfo();
String fileName = null;
try {
fileName = FileUploadUtils.upload(filePath, file, DEFAULT_ALLOWED_EXTENSION);
} catch (InvalidExtensionException e) {
e.printStackTrace();
}
fileInfo.setFilePath(fileName);
fileInfo.setFileName(Name);
return toAjax(fileInfoService.insertHtKnowledgeFileInfo(fileInfo));
}
HTML页面
<div class="col-sm-9">
<input id="uploadFile" name="uploadFile" type="f" multiple>
<input type="button" onclick="uploadFile()" value="上传">
</div>
javascript代码
function uploadFile(isno) {
var formData = new FormData();
formData.append('fileId',$("#fileId").val());
formData.append('fileName', $("#fileName").val());
formData.append('file', $('#file')[0].files[0]);
if (typeof($('#file')[0].files[0]) != 'undefined') {
$.ajax({
url: ctx + "ht/invoice/uploadFile",
type: 'post',
cache: false,
data: formData,
async: false,
processData: false,
contentType: false,
dataType: "json",
});
}
}