transferto方法的应用_Java MultipartFile.transferTo方法代碼示例

transferto方法的应用_Java MultipartFile.transferTo方法代碼示例本文整理匯總了 Java 中 org springframew web multipart MultipartFil transferTo 方法的典型用法代碼示例 如果您正苦於以下問題 JavaMultipar transferTo 方法的具體用法 JavaMultipar transferTo 怎麽用 JavaMultipar transferTo 使用的例子 那麽

本文整理匯總了Java中org.springframework.web.multipart.MultipartFile.transferTo方法的典型用法代碼示例。如果您正苦於以下問題:Java MultipartFile.transferTo方法的具體用法?Java MultipartFile.transferTo怎麽用?Java MultipartFile.transferTo使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.multipart.MultipartFile的用法示例。

在下文中一共展示了MultipartFile.transferTo方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: copyMultipartFileToFile

​點讚 4

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

public static String copyMultipartFileToFile(String baseDir,

MultipartFile multipartFile, String spaceName, String targetFileName)

throws Exception {

if (targetFileName == null) {

return copyMultipartFileToFile(baseDir, multipartFile, spaceName);

}

if (targetFileName.indexOf(“../”) != -1) {

logger.info(“invalid : {}”, targetFileName);

throw new IllegalStateException(“invalid : ” + targetFileName);

}

File file = findTargetFile(baseDir, spaceName, targetFileName);

multipartFile.transferTo(file);

return targetFileName;

}

開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:19,

示例2: doPost

​點讚 3

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

public static String doPost(String id, MultipartFile multipartFile) throws IOException{

OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);

long currentTime = System.currentTimeMillis();

String filename = id + String.valueOf(currentTime)+”.png”;

//創建緩存文件

File f = null;

f = File.createTempFile(“tmp”, null);

multipartFile.transferTo(f);

//緩存文件上傳至OSS

InputStream inputStream = new FileInputStream(f);

ossClient.putObject(“zxbangban”, filename, inputStream);

//關閉OSS實例,刪除臨時文件

ossClient.shutdown();

f.deleteOnExit();

return filename;

}

開發者ID:zxbangban,項目名稱:zxbangban,代碼行數:22,

示例3: uploadFile

​點讚 3

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

/

* 上傳文件

* @param request

* @return

*/

public File uploadFile(HttpServletRequest request) {

CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());

try {

if (multipartResolver.isMultipart(request)) {

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;

Iterator iterator = multiRequest.getFileNames();

while (iterator.hasNext()) {

String key = iterator.next();

MultipartFile multipartFile = multiRequest.getFile(key);

if (multipartFile != null) {

String name = multipartFile.getOriginalFilename();

String pathDir = request.getSession().getServletContext().getRealPath(“/upload/” + DateUtils.currentTime());

File dirFile = new File(pathDir);

if (!dirFile.isDirectory()) {

dirFile.mkdirs();

}

String filePath = pathDir+File.separator+name;

File file = new File(filePath);

file.setWritable(true, false);

multipartFile.transferTo(file);

return file;

}

}

}

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

開發者ID:babymm,項目名稱:mmsns,代碼行數:36,

示例4: uploadFile

​點讚 3

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

public static Boolean uploadFile(HttpServletRequest request, MultipartFile file,String format) {

System.out.println(“開始”);

String path =request.getSession().getServletContext().getRealPath(“/”)+Constant.ZIP_FILE_FOLDER + File.separator;

String fileName = file.getOriginalFilename();

System.out.println(path);

if (format.equals(Constant.FILE_FORMATE_ZIP)) {

File targetFile = new File(path, fileName);

if (!targetFile.exists()) {

targetFile.mkdirs();

}

// 保存

try {

file.transferTo(targetFile);

return true;

} catch (Exception e) {

e.printStackTrace();

return false;

}

}else {

return false;

}

}

開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:25,

示例5: upload

​點讚 3

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@RequestMapping(“/upload.do”)

public String upload(@RequestParam MultipartFile[] myfiles, HttpServletRequest request) throws IOException {

for(MultipartFile file : myfiles){

//此處MultipartFile[]表明是多文件,如果是單文件MultipartFile就行了

if(file.isEmpty()){

System.out.println(“文件未上傳!”);

}

else{

//得到上傳的文件名

String fileName = file.getOriginalFilename();

//得到服務器項目發布運行所在地址

String path1 = request.getSession().getServletContext().getRealPath(“file”)+ File.separator;

// 此處未使用UUID來生成唯一標識,用日期做為標識

String path2 = new SimpleDateFormat(“yyyyMMddHHmmss”).format(new Date())+ fileName;

request.getSession().setAttribute(“document”,path2);

String path = path1+path2;

//查看文件上傳路徑,方便查找

System.out.println(path);

//把文件上傳至path的路徑

File localFile = new File(path);

file.transferTo(localFile);

}

}

return “redirect:/student/uploadDocument”;

}

開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:27,

示例6: multipartFileToTempFile

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

public static boolean multipartFileToTempFile(String fileName,MultipartFile multipartFile){

String destination = fileName;

File file = new File(destination);

try{

multipartFile.transferTo(file);

}catch(Exception e){

return false;

}

return true;

}

開發者ID:forweaver,項目名稱:forweaver2.0,代碼行數:12,

示例7: upload

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

public String upload(MultipartFile file,String path){

//獲取用戶上傳圖片的原始文件名

String originalFilename = file.getOriginalFilename();

//原圖片名為abc.fff.jpg,originalFilename.substring(originalFilename.lastIndexOf(“.”))—>.jpg;所以得+1才能得到jpg

//圖片後綴/格式–>jpg

String extensionFile = originalFilename.substring(originalFilename.lastIndexOf(“.”)+1);

//因為不同的用戶有可能上傳的圖片名一樣,所以我們的圖片名得改成唯一的

String fileName = UUID.randomUUID()+”.”+extensionFile;

logger.info(“開始上傳文件,上傳文件的文件名為{},上傳的路徑為{},新的文件名為{}”,originalFilename,path,fileName);

File fileDir = new File(path);

if (!fileDir.exists()){

//設置文件可寫權限

fileDir.setWritable(true);

//多個級別的文件夾

fileDir.mkdirs();

}

//目標文件

File targetFile = new File(path,fileName);

try {

//將文件上傳到tomcat的upload文件夾下

file.transferTo(targetFile);

//將tomcat上的文件上傳到FTP文件服務器上

FTPUtil.uploadFiles(Lists.newArrayList(targetFile));

//刪除tomcat下的文件,防止tomcat負載過大

targetFile.delete();

} catch (IOException e) {

logger.error(“上傳文件失敗”,e);

return null;

}

return targetFile.getName();

}

開發者ID:wangshufu,項目名稱:mmall,代碼行數:33,

示例8: upload

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@Override

public String upload(final MultipartFile uploadedFile) {

if (uploadedFile.isEmpty()) {

throw new FileUploadException(“Error during upload image. Uploading file is empty!”);

}

final File file = new File(root + “/” + UUID.randomUUID().toString());

try {

uploadedFile.transferTo(file);

return file.getName();

} catch (IOException e) {

throw new FileUploadException(e.getLocalizedMessage());

}

}

開發者ID:akraskovski,項目名稱:product-management-system,代碼行數:14,

示例9: convertIfcToGlb

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@RequestMapping(value = “convertIfcToGlb”, method = RequestMethod.POST)

@ResponseBody

public Map convertIfcToGlb(@RequestParam(value = “file”, required = true) MultipartFile file,

HttpServletRequest request, HttpServletResponse response) throws IOException {//不存檔

ResultUtil result = new ResultUtil();

String path = request.getSession().getServletContext().getRealPath(“upload/ifc/”);

String fileName = file.getOriginalFilename();

String[] split = fileName.split(“\\.”);

String suffix = null;

if (split.length >= 2) {

suffix = split[split.length – 1];

}

if (suffix == null || !suffix.equals(“ifc”)) {

result.setSuccess(false);

result.setMsg(“suffix : ” + suffix + ” is not be supported”);

return result.getResult();

}

String newFileName = fileName.substring(0, fileName.lastIndexOf(“.”));

newFileName += “-” + System.currentTimeMillis();

newFileName += “.” + suffix;

File targetFile = new File(path, newFileName);

if (!targetFile.exists()) {

targetFile.mkdirs();

}

try {

file.transferTo(targetFile);

} catch (Exception e) {

e.printStackTrace();

}

Long glbId = bimService.convertIfcToGlbOffline(targetFile);

result.setSuccess(true);

result.setKeyValue(“glbId”, glbId);;

return result.getResult();

}

開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:36,

示例10: saveFile

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

private void saveFile(MultipartFile picFile, String filePath) throws IOException {

String originalName = picFile.getOriginalFilename();

System.out.print(originalName);

String newFileName = UUID.randomUUID()+originalName.substring(originalName.lastIndexOf(“.”));

File file = new File(filePath,newFileName);

System.out.print(file.getAbsolutePath());

file.createNewFile();

picFile.transferTo(file);

}

開發者ID:hss01248,項目名稱:springMVCDemo,代碼行數:10,

示例11: userRegist

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@RequestMapping(method=RequestMethod.POST)

public ModelAndView userRegist(@Valid User reguser, BindingResult result,

MultipartFile idPicPath,

HttpServletRequest request) throws Exception{

ModelAndView mv = new ModelAndView();

//if(result.hasErrors()){

//mv.setViewName(“useradd”);

//}else{

// ��ȡWebContent����Ŀ¼���·��

String path = request.getServletContext().getRealPath(“/upload”);

// �����ϴ���ͼƬ�ļ�

String fileName = idPicPath.getOriginalFilename(); // ԭʼ�ļ���

// �ļ��� = “����ַ������” + “.��׺��”

String ext = FilenameUtils.getExtension(fileName);

fileName = UUID.randomUUID().toString() + “.” + ext;

//System.currentTimeMillis()

//Math.random() *

File file =

new File(path + “/” + fileName);

idPicPath.transferTo(file); // “���Ϊ”ָ��Ŀ���ļ�

reguser.setIdpicpath(“upload/” + fileName); // �ļ����·��(д����ݿ�)

int count = userService.insertUser(reguser);

if(count > 0) {

// ע��ɹ�����ת���û��б�ҳ��

// �ض��� response.sendRedirect(“/user”);

mv.setViewName(“redirect:/user”);

}else{

mv.setViewName(“useradd”);

}

//}

return mv;

}

開發者ID:Marui0325,項目名稱:y2t187test,代碼行數:37,

示例12: uploadFile

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

/

* 上傳文件處理(支持批量)

* @param request

* @param pathDir 上傳文件保存路徑

* @return

* @throws IllegalStateException

* @throws IOException

*/

public static List uploadFile(HttpServletRequest request,String pathDir) throws IllegalStateException, IOException {

CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(

request.getSession().getServletContext());

List fileNames = InstanceUtil.newArrayList();

if (multipartResolver.isMultipart(request)) {

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;

Iterator iterator = multiRequest.getFileNames();

if(pathDir==null|| pathDir.equals(“”)){

pathDir = request.getSession().getServletContext().getRealPath(uploadFileDir + DateUtils.currentTime());

}

File dirFile = new File(pathDir);

if (!dirFile.isDirectory()) {

dirFile.mkdirs();

}

while (iterator.hasNext()) {

String key = iterator.next();

MultipartFile multipartFile = multiRequest.getFile(key);

if (multipartFile != null) {

String uuid = UUID.randomUUID().toString().replace(“-“, “”);

String name = multipartFile.getOriginalFilename();

int lastIndexOf = name.lastIndexOf(“.”);

String postFix=””;

if(lastIndexOf!=-1){

postFix = name.substring(lastIndexOf).toLowerCase();

}

String fileName = uuid + postFix;

String filePath = pathDir + File.separator + fileName;

File file = new File(filePath);

file.setWritable(true, false);

multipartFile.transferTo(file);

fileNames.add(file.getAbsolutePath());

}

}

}

return fileNames;

}

開發者ID:babymm,項目名稱:mumu,代碼行數:46,

示例13: registerMember

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@Transactional

@Override

public void registerMember(Member vo, HttpServletRequest request) throws Exception {

// 비밀번호 암호화

String encodedPassword = passwordEncoder.encode(vo.getPassword());

vo.setPassword(encodedPassword);

// 파일 업로드 로직을 추가

HttpSession session = request.getSession();

MultipartFile mFile = vo.getUploadFile();

System.out.println(mFile.getSize() + “============” + mFile.isEmpty());

if (mFile.isEmpty() == false) { // 파일 업로드를 했다면

String fileName = mFile.getOriginalFilename();

Date today = new Date();

SimpleDateFormat df = new SimpleDateFormat(“YYYYMMddHHmmssSSS”);

String now = df.format(today);

String newfilename = now + “_” + fileName;

vo.setImgProfile(newfilename); // vo의 완벽한 세팅이 완료

String root = session.getServletContext().getRealPath(“/”);

String path = root + “\\resources\\upload\\”;

File copyFile = new File(path + newfilename);

mFile.transferTo(copyFile); // upload 폴더에 newfilename이 저장

} else {

String defaultImg = “defaultUser.svg”;

vo.setImgProfile(defaultImg);

}

memberDAO.registerMember(vo);

// 권한등록

authoritiesDAO.insertAuthority(new Authority(vo.getUserId(), Constants.ROLE_MEMBER));

}

開發者ID:INSUPARK83,項目名稱:way_learning,代碼行數:30,

示例14: storeIOc

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

private String storeIOc(HttpServletRequest request, MultipartFile file) {

String result = “”;

String realPath = request.getSession().getServletContext().getRealPath(“uploads”);

if (file == null) {

return null;

}

String fileName = “”;

String logImageName = “”;

if (file.isEmpty()) {

result = “文件未上傳”;

} else {

String _fileName = file.getOriginalFilename();

String suffix = _fileName.substring(_fileName.lastIndexOf(“.”));

if(StringUtils.isNotBlank(suffix)){

if(suffix.equalsIgnoreCase(“.xls”) || suffix.equalsIgnoreCase(“.xlsx”) || suffix.equalsIgnoreCase(“.txt”)|| suffix.equalsIgnoreCase(“.png”)

|| suffix.equalsIgnoreCase(“.doc”) || suffix.equalsIgnoreCase(“.docx”) || suffix.equalsIgnoreCase(“.pdf”)

|| suffix.equalsIgnoreCase(“.ppt”) || suffix.equalsIgnoreCase(“.pptx”)|| suffix.equalsIgnoreCase(“.gif”)

|| suffix.equalsIgnoreCase(“.jpg”)|| suffix.equalsIgnoreCase(“.jpeg”)|| suffix.equalsIgnoreCase(“.bmp”)){

// /使用UUID生成文件名稱/

logImageName = UUID.randomUUID().toString() + suffix;

fileName = realPath + File.separator + ATTACH_SAVE_PATH + File.separator + logImageName;

File restore = new File(fileName);

try {

file.transferTo(restore);

result = “/uploads/attach/” + logImageName;

} catch (Exception e) {

throw new RuntimeException(e);

}

}else{

result = “文件格式不對,隻能上傳ppt、ptx、doc、docx、xls、xlsx、pdf、png、jpg、jpeg、gif、bmp格式”;

}

}

}

return result;

}

開發者ID:xujeff,項目名稱:tianti,代碼行數:37,

示例15: transferSpringRequestStreamToHD

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

protected FResult transferSpringRequestStreamToHD(UploadRequest uploadRequest, String saveTempFileDirectory,

HttpServletRequest request) {

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;

Map fileMaps = multiRequest.getFileMap();

if (fileMaps != null && fileMaps.size() == 1) {

for (Entry fileEntry : fileMaps.entrySet()) {

if (fileEntry != null && !fileEntry.getValue().isEmpty()) {

// 得到本次上傳文件

MultipartFile multiFile = fileEntry.getValue();

String originalFilename = multiFile.getOriginalFilename();

uploadRequest.setOriginalExtName(FilenameUtils.getExtension(originalFilename));

String fileName = UUID.randomUUID().toString() + “.” + uploadRequest.getOriginalExtName();

if (StringUtils.isBlank(uploadRequest.getOriginalFilename())) {

uploadRequest.setOriginalFilename(fileName);

} else {

uploadRequest.setOriginalFilename(originalFilename);

}

String fileFullPath = saveTempFileDirectory + File.separator + fileName;

log.debug(“file temp path : ” + fileFullPath);

// 構造臨時文件

File uploadTempFile = new File(fileFullPath);

try {

// 臨時文件持久化到硬盤

multiFile.transferTo(uploadTempFile);

uploadRequest.setTemporaryFilePath(fileFullPath);

uploadRequest.setTemporaryFileSize(uploadTempFile.length());

} catch (IllegalStateException | IOException e) {

log.error(“上傳文件持久化到服務器失敗,計劃持久化文件 “, e);

return FResult.newFailure(HttpResponseCode.SERVER_IO_ERROR, “上傳文件持久化到服務器失敗”);

}

}

}

return FResult.newSuccess(“上傳成功”);

} else {

return FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, “一次請求僅支持上傳一個文件”);

}

}

開發者ID:devpage,項目名稱:fastdfs-quickstart,代碼行數:38,

示例16: uploadFiles

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

/ 上傳文件處理(支持批量) */

public static List uploadFiles(HttpServletRequest request) {

CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(

request.getSession().getServletContext());

List fileNames = InstanceUtil.newArrayList();

if (multipartResolver.isMultipart(request)) {

MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;

String pathDir = getUploadDir(request);

File dirFile = new File(pathDir);

if (!dirFile.isDirectory()) {

dirFile.mkdirs();

}

for (Iterator iterator = multiRequest.getFileNames(); iterator.hasNext();) {

String key = iterator.next();

MultipartFile multipartFile = multiRequest.getFile(key);

if (multipartFile != null) {

FileInfo fileInfo = new FileInfo();

String name = multipartFile.getOriginalFilename();

fileInfo.setOrgName(name);

if (name.indexOf(“.”) == -1 && “blob”.equals(name)) {

name = name + “.png”;

}

String uuid = UUID.randomUUID().toString();

String postFix = name.substring(name.lastIndexOf(“.”)).toLowerCase();

String fileName = uuid + postFix;

String filePath = pathDir + File.separator + fileName;

File file = new File(filePath);

file.setWritable(true, false);

fileInfo.setFileSize(multipartFile.getSize());

try {

multipartFile.transferTo(file);

fileInfo.setFileName(fileName);

fileNames.add(fileInfo);

} catch (Exception e) {

logger.error(name + “保存失敗”, e);

}

}

}

}

return fileNames;

}

開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:42,

示例17: createArticle

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

/

* Create new thread or replay.

*

* @param threadId if null – thread. if not null – replay

* @param boardName

* @param boardId

* @param name

* @param subject

* @param message

* @param file

* @return -1 if already exist or any error >0 if success

*/

public int createArticle(final Integer threadId, Group group,

String name, final String subject, String message, final MultipartFile file) {

int ret_id = -1; //with id

File tmpf = null;

try {

String ct = null;

String fname = null;

if(file != null){

ct = file.getContentType();

fname = file.getOriginalFilename();

tmpf = File.createTempFile(fname, “”);

file.transferTo(tmpf);

}

ArticleWebInput art = ArticleFactory.crAWebInput(threadId, name, subject,

ShortRefParser.shortRefParser(db, message), group, fname, ct);

ArticleForPush article;

if(threadId == null)

article = db.createThreadWeb(art, tmpf);

else

article = db.createReplayWeb(art, tmpf);

if (article == null) //exist

return -1;

else

ret_id = 3; //ok

//peering

FeedManager.queueForPush(article);

} catch (IOException e) {

Log.get().log(Level.SEVERE, “createArticle() failed: {0}”, e);

} catch (StorageBackendException e1) {

Log.get().log(Level.SEVERE, “createArticle() failed: {0}”, e1);

}finally{

if (tmpf != null && tmpf.exists())//not happen if file moved.

tmpf.delete();

}

return ret_id;

}

開發者ID:Anoncheg1,項目名稱:diboard,代碼行數:57,

示例18: addModel

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@RequestMapping(value = “addModel”, method = RequestMethod.POST)

@ResponseBody

public Map addModel(ModelInfoVo modelInfo, @RequestParam(value = “file”, required = true) MultipartFile file,

HttpServletRequest request// , ModelMap model

) {

ResultUtil result = new ResultUtil();

//Long pid = modelInfo.getPid();·

//Project project = projectService.queryProject(pid);

//if (project == null) {

//result.setSuccess(false);

//result.setMsg(“project with pid = ” + pid + ” is null”);

//return result.getResult();

//}

String path = request.getSession().getServletContext().getRealPath(“upload/ifc/”);

String fileName = file.getOriginalFilename();

String[] split = fileName.split(“\\.”);

String suffix = null;

if (split.length >= 2) {

suffix = split[split.length – 1];

}

if (suffix == null || !suffix.equals(“ifc”)) {

result.setSuccess(false);

result.setMsg(“suffix : ” + suffix + ” is not be supported”);

return result.getResult();

}

String newFileName = fileName.substring(0, fileName.lastIndexOf(“.”));

newFileName += “-” + System.currentTimeMillis();

newFileName += “.” + suffix;

File targetFile = new File(path, newFileName);

if (!targetFile.exists()) {

targetFile.mkdirs();

}

try {

file.transferTo(targetFile);

} catch (Exception e) {

e.printStackTrace();

}

modelInfo.setFileName(fileName);

modelInfo.setFileSize(file.getSize());

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

String dateStr = sdf.format(new Date());

modelInfo.setUploadDate(dateStr);

int rid = bimService.addRevision(modelInfo, targetFile);

result.setSuccess(true);

result.setKeyValue(“rid”, rid);

return result.getResult();

}

開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:48,

示例19: processUpload

​點讚 2

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

@RequestMapping(method=RequestMethod.POST)

public String processUpload(@RequestPart(“file”) MultipartFile file) throws IOException {

file.transferTo(new File(“aa.jpg”));

return “redirect:/”;

}

開發者ID:Ulyssesss,項目名稱:java-demo,代碼行數:6,

示例20: uploadFile

​點讚 1

import org.springframework.web.multipart.MultipartFile; //導入方法依賴的package包/類

/

* To upload channel icon.

*

* @param MultipartFile file to upload.

*

* @throws IOException

*/

private void uploadFile(MultipartFile icon) throws IOException {

if (Objects.nonNull(icon)) {

icon.transferTo(new File(imageService.createFileUploadPath(ImageType.department, icon.getOriginalFilename())));

}

}

開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:13,

注:本文中的org.springframework.web.multipart.MultipartFile.transferTo方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/226993.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午10:12
下一篇 2026年3月16日 下午10:12


相关推荐

  • QTreeView使用总结13,自定义model示例,大大优化性能和内存[通俗易懂]

    QTreeView使用总结13,自定义model示例,大大优化性能和内存[通俗易懂]1,简介前面简单介绍过Qt的模型/视图框架,提到了Qt预定义的几个model类型:QStringListModel:存储简单的字符串列表QStandardItemModel:可以用于树结构的存储,提供了层次数据QFileSystemModel:本地系统的文件和目录信息QSqlQueryModel、QSqlTableModel、QSqlRelati…

    2022年5月29日
    43
  • 学生为什么要在CSDN写博客?

    学生为什么要在CSDN写博客?学生为什么要在 CSDN 写博客 引言写博客的好处构建知识体系提升写作能力扩展人脉为简历加分帮助他人为什么是 CSDN 如何写博客记录学习总结错误总结与展望引言就目前来说 学生应该是使用各种博客最多的人 但却不是写博客的主体 在我看来 这是因为学生处于一个学习阶段 在不断的学习和实践的过程中总会遇到这样那样的问题 然后在线下询问无果 或者直接喜欢上网搜索 所以 学生成为了一个使用博客的主体 后者的原因就是因为绝大多数学生认为自己能力不够 没有相关的知识储备 不能够支持自己写博客 这还是在很多人说写博客有非常非常

    2026年3月20日
    2
  • C语言sleep函数与usleep函数

    C语言sleep函数与usleep函数函数名 sleep 头文件 include unistd h 功能 执行挂起指定的秒数语法 unsignedslee unsignedseco 举例 voidfather inti for i 0 i lt 3 i printf father n sleep 1 unistd h

    2026年3月17日
    2
  • BigDecimal.setScale用法总结「建议收藏」

    BigDecimal.setScale用法总结「建议收藏」1. BigDecimalnum1=newBigDecimal(2.225667);//这种写法不允许,会造成精度损失2. BigDecimalnum2=newB

    2022年8月1日
    7
  • mycat读写分离原理_mycat主从复制

    mycat读写分离原理_mycat主从复制前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程首先搭建mysql主从环境,及mycat安装配置mycat的schema.xml文件<?xmlversion=”1.0″?><!DOCTYPEmycat:schemaSYSTEM”schema.dtd”><mycat:schemaxmlns:mycat=”http://io.mycat/”><schemaname=”hbk”ch

    2022年10月13日
    4
  • don\’t have permission access on this server听语音

    don\’t have permission access on this server听语音

    2021年9月23日
    51

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号