springmvc多文件上传
@RequestMapping(value = "/save.api")
@ResponseBody
public String save(MultipartHttpServletRequest req) {
String userId = req.getParameter("user_id");// 钱宝用户id
if (StringUtil.isNotNumber(userId)) {
return jsonpFailed("钱包用户校验错误");
}
String username = req.getParameter("username");// 钱宝用户名
if (StringUtils.isEmpty(username)) {
return jsonpFailed("钱包用户校验错误");
}
String storeName = req.getParameter("storeName");// 门店名称
if (null == storeName || storeName.length() > 10) {
return jsonpFailed("门店名称校验错误");
}
String workingGroupId = req.getParameter("workingGroupId");// 经营类型
if (null == workingGroupId || StringUtil.isNotNumber(workingGroupId)) {
return jsonpFailed("经营类型校验错误");
}
String provinceId = req.getParameter("provinceId");// 省
if (null == provinceId || StringUtil.isNotNumber(provinceId)) {
return jsonpFailed("省校验错误");
}
String cityId = req.getParameter("cityId");// 市
if (null == cityId || StringUtil.isNotNumber(cityId)) {
return jsonpFailed("市校验错误");
}
String areaId = req.getParameter("areaId");// 区
if (null == areaId || StringUtil.isNotNumber(areaId)) {
return jsonpFailed("区校验错误");
}
String detailAddress = req.getParameter("detailAddress");// 详细地址
if (null == detailAddress || StringUtil.isNotNumber(detailAddress)) {
return jsonpFailed("详细地址校验错误");
}
String latitude = req.getParameter("latitude");// 经度
String longitude = req.getParameter("longitude");// 纬度
if (null == latitude || null == longitude
|| !StringUtil.isFloatDigit(latitude)
|| !StringUtil.isFloatDigit(longitude)) {
return jsonpFailed("详细地址校验错误");
}
String ownerName = req.getParameter("ownerName");// 门店负责人姓名
if (null == ownerName || ownerName.length() > 30
|| StringUtil.hasNumberOrSpecialSym(ownerName)) {
return jsonpFailed("门店负责人姓名校验错误");
}
String mobilePhone = req.getParameter("mobilePhone");// 手机号码
if (null == mobilePhone || !StringUtil.isMobile(mobilePhone)) {
return jsonpFailed("手机号码校验错误");
}
MultipartFile facePicture = req.getFile("facePicture");// 门店正面门头照
if (null == facePicture || facePicture.isEmpty()) {
return jsonpFailed("门店正面门头照校验错误");
}
List<MultipartFile> internalPictures = req.getFiles("internalPictures");// 门店内景照
if (null == internalPictures || internalPictures.size() != 3) {
return jsonpFailed("门店内景照校验错误");
}
MultipartFile businessLicense = req.getFile("businessLicense");// 营业执照
if (null == businessLicense || businessLicense.isEmpty()) {
return jsonpFailed("营业执照校验错误");
}
MultipartFile taxRegistrationCertificate = req
.getFile("taxRegistrationCertificate");// 税务登记证
if (null == taxRegistrationCertificate
|| taxRegistrationCertificate.isEmpty()) {
return jsonpFailed("税务登记证校验错误");
}
MultipartFile organizationCode = req.getFile("organizationCode");// 组织机构代码复印件
if (null == organizationCode || organizationCode.isEmpty()) {
return jsonpFailed("组织机构代码复印件校验错误");
}
/**************************************** 可选项 *************************************************/
String openTime = req.getParameter("openTime");// 营业时间
String closeTime = req.getParameter("closeTime");// 营业时间
String perCapita = req.getParameter("perCapita");// 人均
if (StringUtils.hasText(perCapita)) {
if (!StringUtil.isNumber(perCapita)
|| Long.parseLong(perCapita) > 999999) {
return jsonpFailed("人均校验错误");
}
}
String fixedPhoneCode = req.getParameter("fixedPhoneCode");// 门店固话
String fixedPhoneNumber = req.getParameter("fixedPhoneNumber");// 门店固话
if (StringUtils.hasText(fixedPhoneCode)
&& StringUtils.hasText(fixedPhoneNumber)) {
if (!StringUtil.isFixedPhone(fixedPhoneCode + "-"
+ fixedPhoneNumber)) {
return jsonpFailed("门店固话校验错误");
}
}
String qq = req.getParameter("qq");// QQ号
if (StringUtils.hasText(qq)) {
if (!StringUtil.checkQQ(qq)) {
return jsonpFailed("QQ号校验错误");
}
}
String email = req.getParameter("email");// 电子邮箱
if (StringUtils.hasText(email)) {
if (!StringUtil.isEmail(email)) {
return jsonpFailed("电子邮箱校验错误");
}
}
MultipartFile specialLicence = req.getFile("specialLicence");// 特殊行业许可证
String recommendPerson = req.getParameter("recommendPerson");// 推荐人邀请码
ReqStoreInfo reqStore = new ReqStoreInfo();
reqStore.setUserId(Long.parseLong(userId));
reqStore.setUsername(username);
reqStore.setStoreName(storeName);
reqStore.setWorkingGroupId(Long.parseLong(workingGroupId));
reqStore.setProvinceId(Long.parseLong(provinceId));
reqStore.setCityId(Long.parseLong(cityId));
reqStore.setAreaId(Long.parseLong(areaId));
reqStore.setDetailAddress(detailAddress);
reqStore.setOpenTime(openTime);
reqStore.setCloseTime(closeTime);
reqStore.setPer_capita(Integer.parseInt(perCapita));
reqStore.setFixedPhoneCode(Integer.valueOf(fixedPhoneCode));
reqStore.setFixed_phone_number(Integer.valueOf(fixedPhoneNumber));
reqStore.setOwnerName(ownerName);
reqStore.setMobilePhone(mobilePhone);
reqStore.setQq(qq);
reqStore.setEmail(email);
reqStore.setFacePicture(facePicture);
reqStore.setInternalPictures(internalPictures);
reqStore.setBusinessLicense(businessLicense);
reqStore.setTaxRegistrationCertificate(taxRegistrationCertificate);
reqStore.setOrganizationCode(organizationCode);
reqStore.setSpecialLicence(specialLicence);
reqStore.setRecommendPerson(recommendPerson);
reqStore.setAuditorName(getCurrentUserId() + "");
try {
storeService.save(reqStore);
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
return jsonpFailed("保存失败");
} catch (DataValidateException e) {
e.printStackTrace();
log.error(e.getMessage());
return jsonpFailed("保存失败");
}
return jsonpSuccess(null);
}
//多文件上传部分参考自:http://blog.csdn.net/a1314517love/article/details/24183273,http://blog.csdn.net/swingpyzf/article/details/20230865
下一篇: Firebug 1.6b4 发布