深圳住房与城乡建设部网站wordpress模板移植

diannao/2025/10/14 2:43:50/文章来源:
深圳住房与城乡建设部网站,wordpress模板移植,郑州网站建设哪家公司便宜,周到的企业网站建设SpringMVC之文件上传下载 一、文件上传二、文件下载三、多文件上传 一、文件上传 配置多功能视图解析器#xff08;spring-mvc.xml#xff09;#xff1a;在Spring MVC的配置文件#xff08;spring-mvc.xml#xff09;中配置多功能视图解析器#xff0c;以支持文件上传。… SpringMVC之文件上传下载 一、文件上传二、文件下载三、多文件上传 一、文件上传 配置多功能视图解析器spring-mvc.xml在Spring MVC的配置文件spring-mvc.xml中配置多功能视图解析器以支持文件上传。 添加文件上传页面upload.jsp创建一个名为upload.jsp的JSP页面用于用户上传文件。 做硬盘网络路径映射配置服务器的硬盘路径映射到网络路径确保上传的文件可以被访问和处理。 编写一个处理页面跳转的类创建一个处理页面跳转的Java类比如PageController.java或ClazzController.java用于处理上传文件后的页面跳转逻辑。 package com.niyin.web;import com.niyin.biz.tyBiz; import com.niyin.model.ty; import com.niyin.utils.PageBean; import com.niyin.utils.PropertiesUtil; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.IOException; import java.util.List;Controller RequestMapping(/clz) public class tyController {Autowiredprivate tyBiz tyBiz;RequestMapping(/list)public String list(ty t, HttpServletRequest request){PageBean pageBeanagenew PageBean();pageBeanage.setRequest(request);Listty books tyBiz.selectByPager(t, pageBeanage);request.setAttribute(lst,books);request.setAttribute(pageBean,pageBeanage);return list;};RequestMapping(/add)public String add(ty t){int i tyBiz.insertSelective(t);return redirect:list;};RequestMapping(/del)public String del(ty t){tyBiz.deleteByPrimaryKey(t.getTid());return redirect:list;};RequestMapping(/edit)public String edit(ty t){tyBiz.updateByPrimaryKeySelective(t);return redirect:list;};RequestMapping(/preSave)public String preSave(ty t, Model model) {if (t!nullt.getTid()!nullt.getTid()!0){ty ts tyBiz.selectByPrimaryKey(t.getTid());model.addAttribute(ts,ts);}return edit;}RequestMapping(/upload) public String upload(ty t,MultipartFile cfile){try {String dir PropertiesUtil.getValue(dir);String serverPropertiesUtil.getValue(server);String Filename cfile.getOriginalFilename();System.out.println(文件名Filename);System.out.println(文件类别cfile.getContentType());t.setTimage(serverFilename);tyBiz.updateByPrimaryKeySelective(t);FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dirFilename));} catch (IOException e) {e.printStackTrace();}return redirect:list; }RequestMapping(value/download)public ResponseEntitybyte[] download(ty t,HttpServletRequest req){try {//先根据文件id查询对应图片信息 ty ts this.tyBiz.selectByPrimaryKey(t.getTid());String diskPath PropertiesUtil.getValue(dir);String reqPath PropertiesUtil.getValue(server);String realPath ts.getTimage().replace(reqPath,diskPath);String fileName realPath.substring(realPath.lastIndexOf(/)1);//下载关键代码File filenew File(realPath);HttpHeaders headers new HttpHeaders();//http头信息String downloadFileName new String(fileName.getBytes(UTF-8),iso-8859-1);//设置编码headers.setContentDispositionFormData(attachment, downloadFileName);headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);//MediaType:互联网媒介类型 contentType具体请求中的媒体类型信息return new ResponseEntitybyte[](FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);}catch (Exception e){e.printStackTrace();}return null;}RequestMapping(/uploads)public String uploads(HttpServletRequest req, ty t, MultipartFile[] files){try {StringBuffer sb new StringBuffer();for (MultipartFile cfile : files) {//思路//1) 将上传图片保存到服务器中的指定位置String dir PropertiesUtil.getValue(dir);String server PropertiesUtil.getValue(server);String filename cfile.getOriginalFilename();FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dirfilename));sb.append(filename).append(,);}System.out.println(sb.toString());} catch (Exception e) {e.printStackTrace();}return redirect:list;}}package com.niyin.web;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping;Controller public class PageController { RequestMapping(/page/{page}) public String toPage(PathVariable(page) String page){return page; }RequestMapping(/page/{dir}/{page})public String toDirPage(PathVariable(dir) String dir,PathVariable(page) String page){return dir / page;}RequestMapping(/order/presave)public String orderpre() {return /order/presave;}RequestMapping(/clz/presave)public String clzerpre() {return /clz/presave;}}初步模拟上传文件实现一个初步的文件上传功能可以将上传的文件保存到服务器指定的目录。 配置目录的配置文件创建一个配置文件比如resource.properties用于配置上传文件保存的目录。 dirD:/temp/upload/ server/upload/ 最终实现文件上传并显示完成文件上传功能的开发同时可以在页面上显示上传的文件列表或其他相关信息。 二、文件下载 方法代码编写一个方法代码用于处理文件下载请求。该方法根据请求参数或文件路径读取相应的文件并将文件内容写入HTTP响应流中实现文件下载。 package com.niyin.web;import com.niyin.biz.tyBiz; import com.niyin.model.ty; import com.niyin.utils.PageBean; import com.niyin.utils.PropertiesUtil; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.IOException; import java.util.List;Controller RequestMapping(/clz) public class tyController {Autowiredprivate tyBiz tyBiz;RequestMapping(/list)public String list(ty t, HttpServletRequest request){PageBean pageBeanagenew PageBean();pageBeanage.setRequest(request);Listty books tyBiz.selectByPager(t, pageBeanage);request.setAttribute(lst,books);request.setAttribute(pageBean,pageBeanage);return list;};RequestMapping(/add)public String add(ty t){int i tyBiz.insertSelective(t);return redirect:list;};RequestMapping(/del)public String del(ty t){tyBiz.deleteByPrimaryKey(t.getTid());return redirect:list;};RequestMapping(/edit)public String edit(ty t){tyBiz.updateByPrimaryKeySelective(t);return redirect:list;};RequestMapping(/preSave)public String preSave(ty t, Model model) {if (t!nullt.getTid()!nullt.getTid()!0){ty ts tyBiz.selectByPrimaryKey(t.getTid());model.addAttribute(ts,ts);}return edit;}RequestMapping(/upload) public String upload(ty t,MultipartFile cfile){try {String dir PropertiesUtil.getValue(dir);String serverPropertiesUtil.getValue(server);String Filename cfile.getOriginalFilename();System.out.println(文件名Filename);System.out.println(文件类别cfile.getContentType());t.setTimage(serverFilename);tyBiz.updateByPrimaryKeySelective(t);FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dirFilename));} catch (IOException e) {e.printStackTrace();}return redirect:list; }RequestMapping(value/download)public ResponseEntitybyte[] download(ty t,HttpServletRequest req){try {//先根据文件id查询对应图片信息 ty ts this.tyBiz.selectByPrimaryKey(t.getTid());String diskPath PropertiesUtil.getValue(dir);String reqPath PropertiesUtil.getValue(server);String realPath ts.getTimage().replace(reqPath,diskPath);String fileName realPath.substring(realPath.lastIndexOf(/)1);//下载关键代码File filenew File(realPath);HttpHeaders headers new HttpHeaders();//http头信息String downloadFileName new String(fileName.getBytes(UTF-8),iso-8859-1);//设置编码headers.setContentDispositionFormData(attachment, downloadFileName);headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);//MediaType:互联网媒介类型 contentType具体请求中的媒体类型信息return new ResponseEntitybyte[](FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);}catch (Exception e){e.printStackTrace();}return null;}RequestMapping(/uploads)public String uploads(HttpServletRequest req, ty t, MultipartFile[] files){try {StringBuffer sb new StringBuffer();for (MultipartFile cfile : files) {//思路//1) 将上传图片保存到服务器中的指定位置String dir PropertiesUtil.getValue(dir);String server PropertiesUtil.getValue(server);String filename cfile.getOriginalFilename();FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dirfilename));sb.append(filename).append(,);}System.out.println(sb.toString());} catch (Exception e) {e.printStackTrace();}return redirect:list;}} JSP页面代码创建一个JSP页面用于触发文件下载请求。在该页面中可以使用超链接或按钮等方式触发文件下载的方法。 %--Created by IntelliJ IDEA.User: 林墨Date: 2023/9/9Time: 14:20To change this template use File | Settings | File Templates. --% % page contentTypetext/html;charsetUTF-8 languagejava % html headtitle头像上传/title /head body form action${ctx}/clz/upload methodpost enctypemultipart/form-datalabel班级编号/labelinput typetext nametid readonlyreadonly value${param.tid}/br/label班级图片/labelinput typefile namecfile/br/input typesubmit value上传图片/ /formform methodpost action${ctx}/clz/uploads enctypemultipart/form-datainput typefile namefiles multiplebutton typesubmit上传/button/form /body /html效果测试运行应用程序访问下载页面并点击下载链接或按钮验证文件下载功能是否正常工作。 三、多文件上传 jsp页面显示代码修改上传页面upload.jsp支持同时上传多个文件。可以使用HTML的input标签设置multiple属性以允许选择多个文件。 % page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8% !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd html headmeta http-equivContent-Type contenttext/html; charsetUTF-8title博客的编辑界面/title /head body form action${pageContext.request.contextPath }/clz/${empty ts ? add : edit} methodpostid:input typetext nametid value${ts.tid }brbname:input typetext nametname value${ts.tname }brprice:input typetext nametprice value${ts.tprice }brprice:input typetext nametiamge value${ts.timage}brinput typesubmit /form /body /html多文件上传方法修改文件上传处理逻辑使其能够处理同时上传的多个文件。可以使用循环遍历的方式依次处理每个上传的文件。 package com.niyin.web;import com.niyin.biz.tyBiz; import com.niyin.model.ty; import com.niyin.utils.PageBean; import com.niyin.utils.PropertiesUtil; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.IOException; import java.util.List;Controller RequestMapping(/clz) public class tyController {Autowiredprivate tyBiz tyBiz;RequestMapping(/list)public String list(ty t, HttpServletRequest request){PageBean pageBeanagenew PageBean();pageBeanage.setRequest(request);Listty books tyBiz.selectByPager(t, pageBeanage);request.setAttribute(lst,books);request.setAttribute(pageBean,pageBeanage);return list;};RequestMapping(/add)public String add(ty t){int i tyBiz.insertSelective(t);return redirect:list;};RequestMapping(/del)public String del(ty t){tyBiz.deleteByPrimaryKey(t.getTid());return redirect:list;};RequestMapping(/edit)public String edit(ty t){tyBiz.updateByPrimaryKeySelective(t);return redirect:list;};RequestMapping(/preSave)public String preSave(ty t, Model model) {if (t!nullt.getTid()!nullt.getTid()!0){ty ts tyBiz.selectByPrimaryKey(t.getTid());model.addAttribute(ts,ts);}return edit;}RequestMapping(/upload) public String upload(ty t,MultipartFile cfile){try {String dir PropertiesUtil.getValue(dir);String serverPropertiesUtil.getValue(server);String Filename cfile.getOriginalFilename();System.out.println(文件名Filename);System.out.println(文件类别cfile.getContentType());t.setTimage(serverFilename);tyBiz.updateByPrimaryKeySelective(t);FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dirFilename));} catch (IOException e) {e.printStackTrace();}return redirect:list; }RequestMapping(value/download)public ResponseEntitybyte[] download(ty t,HttpServletRequest req){try {//先根据文件id查询对应图片信息 ty ts this.tyBiz.selectByPrimaryKey(t.getTid());String diskPath PropertiesUtil.getValue(dir);String reqPath PropertiesUtil.getValue(server);String realPath ts.getTimage().replace(reqPath,diskPath);String fileName realPath.substring(realPath.lastIndexOf(/)1);//下载关键代码File filenew File(realPath);HttpHeaders headers new HttpHeaders();//http头信息String downloadFileName new String(fileName.getBytes(UTF-8),iso-8859-1);//设置编码headers.setContentDispositionFormData(attachment, downloadFileName);headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);//MediaType:互联网媒介类型 contentType具体请求中的媒体类型信息return new ResponseEntitybyte[](FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);}catch (Exception e){e.printStackTrace();}return null;}RequestMapping(/uploads)public String uploads(HttpServletRequest req, ty t, MultipartFile[] files){try {StringBuffer sb new StringBuffer();for (MultipartFile cfile : files) {//思路//1) 将上传图片保存到服务器中的指定位置String dir PropertiesUtil.getValue(dir);String server PropertiesUtil.getValue(server);String filename cfile.getOriginalFilename();FileUtils.copyInputStreamToFile(cfile.getInputStream(),new File(dirfilename));sb.append(filename).append(,);}System.out.println(sb.toString());} catch (Exception e) {e.printStackTrace();}return redirect:list;}}测试多文件上传通过在上传页面选择多个文件并点击上传按钮测试多文件上传功能是否正常工作。 可以看到已经成功了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/92677.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

域名与网站区别天津网站设计开发

在 MySQL 中,物理拷贝表是一个相对复杂的过程,尤其是与逻辑导出(如使用 mysqldump 或导出 CSV 文件)相比。这个过程涉及直接操作数据库文件,因此需要格外小心。 物理拷贝表的具体步骤: 1、创建相同结构的…

用腾讯云做淘宝客购物网站视频专业简历制作管理平台

目录 一、程序和进程 1、什么是程序? 2、什么是进程? 3、线程是什么? 4、如何查看是多线程还是单线程 5、进程结束的两种情况: 6、进程的状态 二、查看进程信息的相关命令 1、ps:查看静态的进程统计信息 2、…

在线个人资料制作网站智能logo设计网站

需求&#xff1a; 输入连号事件&#xff0c;需要在表格中输入物流单号&#xff0c;物流号码&#xff0c;生成的数量&#xff0c;名称&#xff0c;点击确定自动生成固定数量的连号物流单号 1.页面布局 <div><el-button type"primary" size"default&quo…

企业网站建设流程的第一步工作是自助建站的软件

这两天被 文言(wenyan-lang)刷屏了&#xff0c;这个项目在于使用文言文进行编程&#xff0c;我打算蹭个热度&#xff0c;把年初的作品再捞一捞&#xff0c;即中文SQL。1. 文言Wenyan&#xff1a;吾有一數。曰三。名之曰「甲」。為是「甲」遍。吾有一言。曰「「問天地好在。」」…

网站模板双语wordpress 注册小工具

目录 一、整体框架二、流程代码分析2.1 Boot ROM2.2 Boot Loader2.3 Kernel层Kernel代码部分 2.4 Init进程Init进程代码部分 2.5 zygote进程zygote代码部分 2.6 SystemServer进程SystemServer代码部分 2.7 启动Launcher与SystemUI 三、SystemServices3.1 引导服务3.2 核心服务3…

网站开发企业公司wordpress新语言

文章目录队列简介数组模拟队列&#xff08;无法复用&#xff09;数组模拟环形队列&#xff08;可复用&#xff09;队列简介 队列是一个有序列表&#xff0c;可以用数组或是链表来实现。 遵循先入先出的原则。即先存入队列的数据&#xff0c;先取出&#xff0c;后存入的后取出…

网站访问过程网站域名所有权

1431. 拥有最多糖果的孩子 小白渣翻译 一群孩子手里拿 着不同数目的糖果。你打算额外给每个孩子一些糖果&#xff0c;然后再确定哪些孩子拥有最多的糖果。 给你一个数组 candies &#xff0c;其中 candies[i] 代表第 i 个孩子拥有的糖果数目。另给你一个整数 extraCandies &…

购物网站发展规划与建设进度如何用腾讯云服务器搭建wordpress

一、引言 在Java开发领域&#xff0c;三大框架——Spring、Hibernate和MyBatis&#xff0c;各自扮演着重要的角色。它们为开发者提供了不同的解决方案&#xff0c;使得开发者能够更高效地构建企业级应用。本文将分别介绍这三大框架的特点、优势以及适用场景&#xff0c;并对它…

门户网站定义谷歌网站排名

一只青蛙想要过河。 假定河流被等分为 x 个单元格&#xff0c;并且在每一个单元格内都有可能放有一石子&#xff08;也有可能没有&#xff09;。 青蛙可以跳上石头&#xff0c;但是不可以跳入水中。 给定石子的位置列表&#xff08;用单元格序号升序表示&#xff09;&#xff…

cdr做网站怎么导出告别厅北京告别厅

OD统一考试(B卷) 分值: 100分 题解: Java / Python / C++ 题目描述 某组织举行会议,来了多个代表团同时到达,接待处只有一辆汽车可以同时接待多个代表团,为了提高车辆利用率,请帮接待员计算可以坐满车的接待方案输出方案数量。 约束: 一个团只能上一辆车,并且代表团…

做网站建设的好处团购网站建设流程

动机 由于某些类型的固有的实现逻辑&#xff0c;使得它们具有两个变化的维度&#xff0c;乃至多个变化的维度。 如何应对这种“多维度的变化”&#xff1f;如何利用面向对象技术来使得类型可以轻松地沿着两个乃至多个方向变化&#xff0c;而不引入额外的复杂度 举个栗子 我们…

建设一个网站的硬件要求广西美丽乡村建设网站

一、环境搭建 1、安装nodejs #下载地址 https://nodejs.org/dist/v20.9.0/node-v20.9.0-x64.msi 2、配置环境变量 上面下载完安装包后自行安装&#xff0c;安装完成后安装下图操作添加环境变量 #查看版本 node --version v20.9.0# npm --version 10.1.03、配置npm加速源 np…

做网站引流的最佳方法山西建设行政主管部门官方网站

在弱电施工中&#xff0c;设备调试是一个很重要的环节&#xff0c;施工这么久就是为了实现弱电各系统的功能&#xff0c;调试是每一个弱电人系必需会的技能&#xff0c;也是检验你结合能力一种体现。在调试中会遇到各种你想不到的问题&#xff0c;当遇到问题时&#xff0c;你应…

专门做诺丽果的网站增城专业建站公司

本文将介绍如何使用 2-3 句指令在几分钟内创建一个 Web IDE 环境。服务器准备如何准备服务器可以参考上文 一键体验 Istio&#xff0c;这里只需要一台即可&#xff0c;示例中的服务器 IP 为&#xff1a;43.154.189.116安装 Web IDE下载安装工具在服务器上&#xff0c;执行以下指…

深圳专业制作网站技术wordpress人才主题

转自&#xff1a; https://www.zhihu.com/question/21329754 分类和回归的区别在于输出变量的类型。 定量输出称为回归&#xff0c;或者说是连续变量预测&#xff1b; 定性输出称为分类&#xff0c;或者说是离散变量预测。 举个例子&#xff1a; 预测明天的气温是多少度&…

蓬莱有做网站的吗网站加入百度广告联盟

Android 消息处理机制&#xff1a;Handler|Message

wordpress站点搬家男女做网站

今天我刚好要做一个单页面来展示某些东西。 就一起来看看吧&#xff0c;初学者写的不好请自闭双眼。 先上代码吧&#xff0c;大家看看有什么需要修改的地方。 1 <!DOCTYPE html>2 <html lang"en">3 4 <head>5 <meta charset"UTF-8&q…

微网站 方案贵州住房和城乡建设局网站

网络安全投资和准备被视为推动企业发展的关键因素。除了避免损失之外&#xff0c;高管还应利用有效的以业务为中心的安全方法&#xff0c;通过大规模实现敏捷性和创新来推动收入增长。 主要发现 高增长公司通过扩大商业足迹来推动业绩&#xff0c;这需要大规模的创新、敏捷性和…

南京 外贸网站建设WordPress刷下载量

随着春风的温柔拂面&#xff0c;我们即将迎来一年一度的三八国际妇女节。这个特别的日子&#xff0c;不仅是对女性贡献的认可和庆祝&#xff0c;也是向我们生命中的女性表达感激和爱意的绝佳时机。在这个充满温馨和敬意的时刻&#xff0c;我们常常在思考&#xff0c;如何用一份…

商业平台网站开发网站的折线图怎么做

转自本人在知乎上面的答案印如意Fitz 通过往邮箱发送邮件&#xff0c;从而达到控制电脑or开始抓取数据or播放音乐等系列操作。 like that: 先用我的常用邮箱给我备胎邮箱发送一封主题为“shutdown”的邮件 然后我要关机的电脑检测到了自动关机并发挥一封主题为“already shutdo…