获取不到formData中的 value值
来源:4-13 前后端联调验证整体模块功能
小全灬
2019-05-03
这样MultipartResolver 配置生效了吗? request 已经是defaultmultiparthttpservletrequest 了,但是完全获取不到shopStr啊
写回答
1回答
-
同学应该还是哪里配置有问题,可能是js名字对不上,也可能是spring-web.xml没有配置正确,可以直接复制粘贴我的,改改路径,清空页面缓存,然后试试,成功后,再对比下差距在哪里
/** * */ $(function(){ var initUrl = '/o2o/shopadmin/getshopinitinfo'; var registerShopUrl = '/o2o/shopadmin/registershop'; alert(initUrl); getShopInitInfo(); function getShopInitInfo(){ $.getJSON(initUrl,function(data){ if(data.success){ var tempHtml = ''; var tempAreaHtml = ''; data.shopCategoryList.map(function(item,index){ tempHtml += '<option data-id="' + item.shopCategoryId + '">' + item.shopCategoryName+'</option>'; }); data.areaList.map(function(item,index){ tempAreaHtml += '<option data-id="' + item.areaId + '">' +item.areaName +'</option>'; }); $('#shop-category').html(tempHtml); $('#area').html(tempAreaHtml); } }); $('#submit').click(function(){ var shop = {}; shop.shopName = $('#shop-name').val(); shop.shopAddr = $('#shop-addr').val(); shop.phone = $('#shop-phone').val(); shop.shopDesc = $('#shop-desc').val(); shop.shopCategory = { shopCategoryId : $('#shop-category').find('option').not(function(){ return !this.selected; }).data('id') }; shop.area = { areaId : $('#area').find('option').not(function(){ return !this.selected; }).data('id') }; var shopImg = $('#shop-img')[0].files[0]; var formData = new FormData(); formData.append('shopImg',shopImg); formData.append('shopStr',JSON.stringify(shop)); var verifyCodeActual = $('#j_captcha').val(); if (!verifyCodeActual) { $.toast('请输入验证码!'); return; } formData.append('verifyCodeActual',verifyCodeActual); $.ajax({ url : registerShopUrl, type : 'POST', data : formData, contentType : false, processData : false, cache : false, success : function(data){ if(data.success){ $.toast('提交成功!'); }else{ $.toast('提交失败!' + data.errMsg); } $('#captcha_img').click(); } }); }); } })
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 配置SpringMVC --> <!-- 1.开启SpringMVC注解模式 --> <mvc:annotation-driven /> <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 --> <mvc:resources mapping="/resources/**" location="/resources/" /> <mvc:default-servlet-handler /> <!-- 3.定义视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/html/"></property> <property name="suffix" value=".html"></property> </bean> <!-- 文件上传解析器 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"></property> <!-- 1024 * 1024 * 20 = 20M --> <property name="maxUploadSize" value="20971520"></property> <property name="maxInMemorySize" value="20971520"></property> </bean> <!-- 4.扫描web相关的bean --> <context:component-scan base-package="com.imooc.o2o.web" /> </beans>
012019-05-04
相似问题