前段页面:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html >
<html>
<head>
<title>个人信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0;user-scalable=no" name="viewport">
<meta content="640" name="MobileOptimized">
<meta content="YES" name="apple-touch-fullscreen">
<meta content="yes" name="apple-mobile-web-app-capable">
<link href="${ROOT_PATH }content/css/staff/employee.css" type="text/css" rel="stylesheet"/>
<link href="${ROOT_PATH }content/css/staff/font-awesome.min.css" type="text/css" rel="stylesheet"/>
<script src="${ROOT_PATH }content/scripts/jquery-1.10.1.min.js"></script>
<script src="${ROOT_PATH }content/scripts/jquery.form.js"></script>
<script src="${ROOT_PATH }content/scripts/staff/staff.js"></script>
</head>
<body>
<form action="${ROOT_PATH }Staff/index/upload" name="stafform" id="stafform" method="post">
<c:set var="head" value="${ROOT_PATH }content/images/staff/photo.png"/>
<c:if test="${!empty staff.imageurl.value }">
<c:set var="head" value="${staff.imageurl.value }"/>
</c:if>
<c:set var="headx" value="${ROOT_PATH }content/images/staff/img1.jpg"/>
<c:if test="${!empty staff.imageurlb.value }">
<c:set var="headx" value="${staff.imageurlb.value }"/>
</c:if>
<div class="avatar"><a class="photo" href="#"><img id="imghead" src="${head}"/><input id="imagev" name="image" onchange="previewImage(this)" type="file" class="photo_put" value="" /></a><input type="text" name="hm" value="${staff.staffename.value}"/></div>
<div class="per_infor_box">
<ul class="per_infor">
<li><label>门 店</label><input type="text" value="${staff.commpanyName.value}" disabled="disabled" /></li>
<li><label>职 位</label><input type="text" value="${staff.position.value }" disabled="disabled"/></li>
<li><label>姓 名</label><input type="text" value="${staff.staffname.value }" disabled="disabled"/></li>
<li><label>手 机</label><input type="text" value="${staff.mobilephone.value }" disabled="disabled"/></li>
<li><label>工 龄</label><input type="text" value="${staff.workTime.value }" disabled="disabled"/></li>
<li><label>身份证</label><input type="text" value="${staff.pccid.value }" disabled="disabled"/></li>
<li><label>自我介绍</label><textarea disabled="disabled">${staff.description.value }</textarea></li>
</ul>
</div>
<div class="bottom infor_bot">
<input class="present" type="submit" value="提 交"/>
</div>
</form>
</body> <script type="text/javascript">
$(function () {
$('#stafform').submit(function () {
var options = {
dataType: 'json',
success: function (txt) {
if (txt.isok) {
alert("保存成功");
location.reload(true);
return false;
} else {
alert(txt.data);
return false;
}
}
};
$('#stafform').ajaxSubmit(options);
return false;
});
});
</script>
</html>

后台代码:

package amani.wechat.platform.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map; import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.xml.bind.JAXBElement; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; import amani.wechat.platform.controller.model.Result;
import amani.wechat.platform.services.ICommonService;
import amani.wechat.platform.utils.CompressPic;
import amani.wechat.platform.webserviceClient.StaffHairDesignerInfo;
import amani.wechat.platform.webserviceClient.Staffinfo;
import amani.wechat.platform.webserviceClient.imageService.ImageCloudService;
import amani.wechat.platform.webserviceClient.imageService.ImageCloudServicePortType; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; @Controller
@RequestMapping("/Staff")
public class StaffController { @Resource(name="CommonService")
ICommonService commonService ; static ImageCloudServicePortType aImageCloudServicePortType; static{
ImageCloudService aImageCloudService = new ImageCloudService();
aImageCloudServicePortType = aImageCloudService.getImageCloudServiceHttpPort();
}
/**
* 更新头像和昵称
* @param image
* @param hm
* @param session
* @return
* @throws IOException
*/
@RequestMapping(value = "/index/upload", method = RequestMethod.POST)
@ResponseBody
public Result indexUpload(@RequestParam(value = "file", required = false)MultipartFile image, String hm, HttpSession session) {
String imagePath = "";
String imagebPath = "";
Result res = new Result();
String openid = session.getAttribute("openid")+"";
res.setIsok(true);
if(image!=null){
String fileName = new Date().getTime() + "_" + image.getOriginalFilename();
String key = fileName;
try {
byte[] img = CompressPic.compressPic(image.getInputStream(), 300, 300);
imagePath = aImageCloudServicePortType.uploadFile(img, "amani", key);
Gson gson = new Gson();
Map<String, String> map = gson.fromJson(imagePath, new TypeToken<Map<String, String>>(){}.getType());
imagePath = map.get("url");
} catch (Exception e) {
e.printStackTrace();
}
}
commonService.updateStaffInfo(openid, hm, imagePath, imagebPath); return res;
}
}

改成

@RequestParam(value = "file",就ok了

最新文章

  1. 默认.htpl改为.htpl
  2. MongoDB学习:(二)MongoDB简单使用
  3. sql server 2008 提示评估期已过的解决方法(升级无效)
  4. HDOJ 1312题Red and Black
  5. a标签无disabled属性
  6. .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index&quot;的问题
  7. python - XML文件及其操作
  8. Mapper映射语句高阶应用——ResultMap
  9. Android九宫格图片(9.png)的讲解与制作
  10. hdu 5446 Unknown Treasure 中国剩余定理+lucas
  11. English - 定冠词和不定冠词(a an the) 的区别
  12. 在python中单线程,多线程,多进程对CPU的利用率实测以及GIL原理分析
  13. 怎么样获取小米手机4的ROOT超级权限
  14. POI如何自动调整Excel单元格中字体的大小
  15. python小结 1
  16. Build Tool(构建工具)
  17. Python3实战系列之四(获取印度售后数据项目)
  18. DevExpress11、TreeList
  19. const变量指针赋值给非const类型的指针运行结果
  20. 前端小结(5)---- iframe

热门文章

  1. MVC使用JCrop上传、裁剪图片
  2. [转载]typedef struct和struct的区别
  3. 做iphone5适配时,一定要做好图片大小的调整。
  4. Jquery源码分析之匿名函数的自执行
  5. Android网络请求之OkHttp框架
  6. 混沌数学之Chua&#39;s circuit(蔡氏电路)
  7. 第二章 Jackson属性名转换+属性忽略
  8. Linux C Socket编程原理及简单实例
  9. linux下永久添加静态路由
  10. JS 中数组字符串索引和数值索引研究