SpingMvc上传文件File遇到的坑爹bug

SpingMvc上传文件File遇到的坑爹bug
出bug前的代码片段

<div id="dlg" class="easyui-dialog" style="width: 670px;height: 500px;padding: 10px 20px"
  closed="true" buttons="#dlg-buttons">
  <form id="fm" method="post"  enctype="multipart/form-data">
  	<table cellspacing="8px;">
  		<tr>
  			<td>商品名称:</td>
  			<td colspan="4"><input class="easyui-validatebox" id="name" name="name"  required="true" style="width: 300px;"/></td>
  		</tr>
  		<tr>
  			<td>价格:</td>
  			<td colspan="4"><input class="easyui-validatebox" id="price" name="price"  required="true"/></td>
  		</tr>
  		<tr>
  			<td>库存:</td>
  			<td colspan="4"><input class="easyui-validatebox" id="stock" name="stock"  required="true"/></td>
  		</tr>
  		<tr>
  			<td>商品图片:</td>
  			<td colspan="4"><input id="pP"   name="proPic"  type="file"/></td>
  		</tr>
  	    <tr>
  			<td>所属大类:</td>
  			<td colspan="4"><input class="easyui-combobox" id="bName" name="bigType.id"  data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/admin/bigType/comboList.do'"/></td>
  		</tr>
  		<tr>
  			<td>所属小类:</td>
  			<td colspan="4"><input class="easyui-combobox"  id="sName" name="smallType.id" data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/admin/smallType/comboList.do'" /></td>
  		</tr>
  		<tr>
  			<td valign="top">备注:</td>
  			<td colspan="4">
  				<textarea rows="7" cols="50" name="description" id="description"></textarea>
  				<input type="hidden"  id="proPic" name="proPic" />
  				<input type="hidden"  id="hot"  name="hot"/>
  				<input type="hidden"  id="specialPrice" name="specialPrice" />
  				<input type="hidden"  id="hotTime" name="hotTime" />
  				<input type="hidden"  id="specialPriceTime" name="specialPriceTime" />
  			</td>
  		</tr>
  	</table>
  </form>
</div>
@RequestMapping("/save")
	public String save(Product product,@RequestParam(value="proPic",required=false) MultipartFile proPic,HttpServletRequest request,HttpServletResponse response)throws Exception{
		if(!proPic.isEmpty()) {
			String filePath = request.getServletContext().getRealPath("/");
			String imageName=DateUtil.getCurrentDateStr()+"."+proPic.getOriginalFilename().split("\\.")[1];
			proPic.transferTo(new File(filePath+"static/images/product/"+imageName));
			product.setProPic(imageName);
		}
		int resultTotal = productService.saveProduct(product);
		JSONObject result = new JSONObject();
		if(resultTotal>0) {
			result.put("success", true);
		}else {
			result.put("success", false);
		}
		ResponseUtil.write(response, result);
		return null;
	}

试了一天一直报错在这里插入图片描述
试了很多方法不管用,后来将proPic改为其他字母image,不与实体类里的字段相同,就能起作用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值