spring框架上传文件
来源:互联网 发布:飞行员燃料走淘宝 编辑:程序博客网 时间:2024/05/22 13:19
页面代码(使用的是freemark页面):
主要代码:
<form name="createApp" action="new.html" method="post" enctype="multipart/form-data">
<pre name="code" class="html">应用logo:<input type = "file" name = "appLogo">
<body> <p>-------------能力包信息列表-----------------</p> <#list allPackets as packet> <p>能力包编号: ${packet.code} 能力包名称: ${packet.name} 能力包描述: ${packet.desc} </p></#list><br/><form name="createApp" action="new.html" method="post" enctype="multipart/form-data">应用名:<input type = "text" name="appName"/>应用描述:<input type = "text" name = "appDesc">回调地址:<input type = "text" name = "callback">申请人姓名:<input type = "text" name = "appCName">申请人联系方式:<input type = "text" name = "appCPhone">应用logo:<input type = "file" name = "appLogo"><br/> <#list allPackets as packet> <input type="checkbox" name="packetCodes" value="${packet.code}"/>能力包编号:${packet.code}<br/> </#list> <input type="submit" name="submit" value="提交"></form></body>
<#list allPackets as packet> <input type="checkbox" name="packetCodes" value="${packet.code}"/>能力包编号:${packet.code}<br/> </#list>上面这行代码的作用是列出能力包数组,然后选择列出选择框,将选择的能力包Code数组提交。
下面是接受form表单传输的数据:在viewCreateApp类中定义一个List<String>数组就可以接受能力包Code数组。
@RequestMapping(value = "/new",method = RequestMethod.POST)public String newApp(ViewCreateApp viewCreateApp) throws IOException{/*InputStream input = appLogo.getInputStream();String logoPath = "/opt/attachment/1.jpg";//TODO viewCreateApp.setLogoPath(logoPath);String partnerCode = "";//TODO 添加partnerCode从session中获取的。*/Date date = new Date(); byte[] appLogoData = viewCreateApp.getAppLogo().getBytes();viewCreateApp.setCreateDate(date);viewCreateApp.setStatus(AppStatus.s0);viewCreateApp.setLogoPath("/12.jpg");AppService.createAttach("20",appLogoData);//Boolean isCreate = AppService.create(viewCreateApp);////if (isCreate) {//return "redirect:createAppSuccess";//} else {//return "redirect:createAppFailure";//}return "redirect:createAppSuccess";}在viewCreateApp类中定义MultipartFile 文件来接受上传的文件
private MultipartFile appLogo;
byte[] appLogoData = viewCreateApp.getAppLogo().getBytes();这样就将上传的文件转化成byte数组。
0 0
- spring框架上传文件
- 使用spring MVC框架进行文件上传
- 使用spring MVC框架进行文件上传
- 使用spring MVC框架进行文件上传
- 使用spring MVC框架进行文件上传
- 使用spring MVC框架进行文件上传
- 文件上传--基于Spring MVC框架+SmartUpload
- 使用Spring框架实现文件上传
- java基于spring框架上传文件
- Spring-Mvc框架实现文件上传
- Spring框架文件上传的问题
- HAP框架+spring MVC下上传文件
- Spring mvc框架的web上传文件文档
- Spring Web MVC框架(五) 文件上传
- (文件)图片上传,Spring或SpringMVC框架
- spring和mybatis框架中实现文件上传功能
- Spring框架中自带的文件上传
- CI框架文件上传
- 【Redis 2】Redis数据库的学习与实践—redis的数据类型
- HDU 3395 Special Fish(费用流)
- css样式大全(整理版)
- 一个xml引起的三方Camera应用不能使用问题
- Oracle执行计划详解
- spring框架上传文件
- Eclipse配置JBoss的方法
- jsp伪静态技术
- QML类型说明-GridLayout
- 一张图告诉你,只会JavaScript还不够!
- CSDN Android客户端的制作
- NAL unit syntax
- xshell入门使用教程
- 怎样制作基于Cocos2d-x的SLG游戏-第2章(双指缩放,单指拖动的实现)