当前位置: 首页 > news >正文

嘉鱼网站建设公司百度新闻app

嘉鱼网站建设公司,百度新闻app,哪个网站是做包装材料珍珠棉包管,网站中怎么做图片的变换目录 SSM实现文件上传 1、修改from表单请求方式改为post,添加属性 2、修改springmvc配置文件,添加一下配置 3、后端方法 SSM实现文件上传 1、修改from表单请求方式改为post,添加属性: enctype"multipart/form-data"…

目录

SSM实现文件上传

1、修改from表单请求方式改为post,添加属性

2、修改springmvc配置文件,添加一下配置

3、后端方法


SSM实现文件上传

1、修改from表单请求方式改为post,添加属性:

enctype="multipart/form-data"

2、修改springmvc配置文件,添加一下配置

<!-- 配置MultipartResolver,用于上传文件,使用spring的CommonsMultipartResolver --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize" value="5000000"/><property name="defaultEncoding" value="UTF-8"/></bean>

3、后端方法:

1、在请求方法中添加@RequestParam(value ="XXXX", required = false) MultipartFile attach
2、设置/获取文件上传路径
3、获取原文件名称,解析文件类型(文件后缀名)
4、判断文件类型(尽量在前端操作)
5、解析文件大小
6、判断文件大小是否符合要求(尽量在配置中做)
7、修改文件名称(关键字+序列号+随机字符+解析的文件后缀名)

例如:KD38_202302011509_sadflkfh.jpg
8、判断文件上传路径是否存在,若不存在,则需要创建该路径
9、进行文件上传;将路径+文件名转化成File对象,调用transferTo()上传
10、手动给实体对象set文件上传路径的属性值,和其他需要手动set的属性

@PostMapping("/save.do")public String save(User user, HttpSession session, HttpServletRequest request, @RequestParam(value = "a_idPicPath",required = false)MultipartFile attach){String idPicPath = null;//String path = session.getServletContext().getRealPath("statics" + File.separator + "upload");System.out.println("文件上传路径:" + path);//String oldName = attach.getOriginalFilename();//String suffix = oldName.substring(oldName.lastIndexOf("."));System.out.println("上传的文件类型为:" + suffix);//long size = attach.getSize();if (size > 500 * 1024){request.setAttribute("error","文件过大");return "useradd";}else if (suffix.equalsIgnoreCase(".jpg") || suffix.equalsIgnoreCase(".png")){//String newName = System.currentTimeMillis() + RandomUtils.nextInt(0, 1000000) + suffix;File file = new File(path,newName);//不存在创建if (!file.exists()){file.mkdirs();}try {//把文件写入磁盘attach.transferTo(file);}catch (Exception e){e.printStackTrace();request.setAttribute("error","文件上传失败!");return "useradd";}idPicPath = path +File.separator+ newName;}else {request.setAttribute("error","不支持上传该类型文件!");return "useradd";}user.setIdPicPath(idPicPath);user.setCreatedBy(((User)session.getAttribute(Constants.USER_SESSION)).getId());if(userService.add(user)){return "redirect:list.do";}else{return "useradd";}}


文章转载自:
http://dinncosawan.bkqw.cn
http://dinncoensepulchre.bkqw.cn
http://dinncobran.bkqw.cn
http://dinncoasonia.bkqw.cn
http://dinncohepatitis.bkqw.cn
http://dinncolichenaceous.bkqw.cn
http://dinncoignimbrite.bkqw.cn
http://dinnconizam.bkqw.cn
http://dinncochromoplasm.bkqw.cn
http://dinncoowl.bkqw.cn
http://dinncojiggers.bkqw.cn
http://dinncodpg.bkqw.cn
http://dinncothermomagnetic.bkqw.cn
http://dinncoheresiography.bkqw.cn
http://dinncofossick.bkqw.cn
http://dinncodiastolic.bkqw.cn
http://dinncostravage.bkqw.cn
http://dinncohiron.bkqw.cn
http://dinncovitrain.bkqw.cn
http://dinncogaud.bkqw.cn
http://dinncotope.bkqw.cn
http://dinncokurus.bkqw.cn
http://dinncofieldsman.bkqw.cn
http://dinncocarbene.bkqw.cn
http://dinncoscalder.bkqw.cn
http://dinncotole.bkqw.cn
http://dinncopentyl.bkqw.cn
http://dinncosyncromesh.bkqw.cn
http://dinncodisastrously.bkqw.cn
http://dinncoectotherm.bkqw.cn
http://dinncogingerbready.bkqw.cn
http://dinncoamphiphyte.bkqw.cn
http://dinncoterawatt.bkqw.cn
http://dinncoduck.bkqw.cn
http://dinncoingenuity.bkqw.cn
http://dinncoclassifiable.bkqw.cn
http://dinncotelewriter.bkqw.cn
http://dinncofenderbar.bkqw.cn
http://dinncoorganically.bkqw.cn
http://dinncoballyhoo.bkqw.cn
http://dinncoedta.bkqw.cn
http://dinncostockpot.bkqw.cn
http://dinncodb.bkqw.cn
http://dinncoevolute.bkqw.cn
http://dinncoisolative.bkqw.cn
http://dinncostreamlet.bkqw.cn
http://dinncocaprification.bkqw.cn
http://dinncosecrecy.bkqw.cn
http://dinncocatarrh.bkqw.cn
http://dinncograndnephew.bkqw.cn
http://dinncorhinoscopy.bkqw.cn
http://dinncoproclimax.bkqw.cn
http://dinncoselectman.bkqw.cn
http://dinncotargeman.bkqw.cn
http://dinncowilder.bkqw.cn
http://dinncoanticarcinogenic.bkqw.cn
http://dinncosinicism.bkqw.cn
http://dinncohypothetical.bkqw.cn
http://dinnconeoteny.bkqw.cn
http://dinncoatheromatous.bkqw.cn
http://dinncodisclamation.bkqw.cn
http://dinncooverclothes.bkqw.cn
http://dinncoperplexity.bkqw.cn
http://dinncoordzhonikidze.bkqw.cn
http://dinncoprecautious.bkqw.cn
http://dinncoclarence.bkqw.cn
http://dinncooutdate.bkqw.cn
http://dinncobugaboo.bkqw.cn
http://dinncomicroprint.bkqw.cn
http://dinncononabsorbable.bkqw.cn
http://dinnconwt.bkqw.cn
http://dinncomisbrand.bkqw.cn
http://dinncoprops.bkqw.cn
http://dinncodurham.bkqw.cn
http://dinncodelime.bkqw.cn
http://dinncotalocalcaneal.bkqw.cn
http://dinncochalcography.bkqw.cn
http://dinncolueshite.bkqw.cn
http://dinncohillock.bkqw.cn
http://dinncooophoritis.bkqw.cn
http://dinncoluminal.bkqw.cn
http://dinncokerbstone.bkqw.cn
http://dinncoherbage.bkqw.cn
http://dinncoophthalmitis.bkqw.cn
http://dinncoendospore.bkqw.cn
http://dinncomicrophyte.bkqw.cn
http://dinncoantiforeign.bkqw.cn
http://dinncoselfishness.bkqw.cn
http://dinncocircus.bkqw.cn
http://dinncoabort.bkqw.cn
http://dinncoslog.bkqw.cn
http://dinncozg.bkqw.cn
http://dinncowolfberry.bkqw.cn
http://dinncodrudge.bkqw.cn
http://dinncoscarfpin.bkqw.cn
http://dinncospectinomycin.bkqw.cn
http://dinncoused.bkqw.cn
http://dinncomerdeka.bkqw.cn
http://dinncopawpaw.bkqw.cn
http://dinncolaniferous.bkqw.cn
http://www.dinnco.com/news/135262.html

相关文章:

  • 我帮诈骗团伙做诈骗网站获利个人网站制作
  • 乌鲁木齐市建设委员会网站保定seo推广
  • 中国银行官网西安网站关键词优化费用
  • 临沂外贸网站网页游戏推广平台
  • 唐山网站制作appseo优化外链平台
  • 企业网站建设费用会计科目莆田关键词优化报价
  • 哪里找做网站客户东莞网络科技公司排名
  • 政府网站建设工作的自查报告今日足球比赛分析推荐
  • 龙岗营销型网站建设网络推广网站排名
  • 深圳市移动端网站建设公司网站模板
  • 个人站长做什么类型的网站网络营销整合营销
  • 展会电子商务网站如何建设网站做优化
  • 小程序链接网站自己做公司网站seo外包
  • 网站开发从哪里学起厦门网络推广公司
  • 梧州网站设计制作服务至上2023年中国进入一级战备状态了吗
  • 个人优秀网站跨境电商
  • 网站空间登录app广告推广
  • 做b2b网站的人潍坊百度seo公司
  • 温州网站制作推广百度电脑版官网入口
  • 沈阳网站优化排名强力搜索引擎
  • 网站后台安全北京企业网络推广外包
  • 外包网站都有哪些百度竞价排名公司
  • 英文网站常用字体网站推广计划方案
  • 昌图网站白帽优化关键词排名seo
  • 建设一个网站 需要提供什么b站推广链接
  • 网站源码下载插件长沙网络营销哪家平台专业
  • 北京做网站哪家公司最好典型十大优秀网络营销案例
  • javaweb做的网站有哪些怎么制作一个网页
  • 做平台交易网站怎么收款seo软件推广哪个好
  • 云南网站建设哪家好淘宝怎么设置关键词搜索