前后端调试的时候获取不到shopCategoryId

来源:4-13 前后端联调验证整体模块功能

慕勒2534496

2019-05-13

找了好久都没找到问题所在,求助!谢谢老师。附上部分代码:
图片描述
描述:可以显示下拉菜单,但是获取店铺信息的时候获取不到shopCategoryId。

shopoperation.js

$(function() {
var initUrl = ‘/o2o/shopadmin/getshopinitinfo’;
var registerShopUrl = ‘/o2o/shopadmin/registershop’;
getShopInitInfo();
function getShopInitInfo() {
$.getJSON(initUrl, function(data) {
if (data.success) {
var tempHtml = ‘’;
var tempAreaHtml = ‘’;
data.shopCategoryList.map(function(item, index) {
tempHtml += ‘’ + item.shopCategoryName + ‘’;
});
data.areaList.map(function(item, index) {
tempAreaHtml += ‘’
+ item.areaName + ‘’;
});
$(’#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 = KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲shop-img')[0].f…(’#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(‘提交成功!’);
if (!isEdit) {
}
} else {
$.toast(‘提交失败!’ + data.errMsg);
}
// 点击验证码图片的时候,注册码会改变
$(’#captcha_img’).click();
}
});
});
}
})

ShopManagementController.java
@Controller
@RequestMapping("/shopadmin")
public class ShopManagementController {
@Autowired
private ShopService shopService;
@Autowired
private ShopCategoryService shopCategoryService;
@Autowired
private AreaService areaService;

@RequestMapping(value = "/getshopinitinfo", method = RequestMethod.GET)
@ResponseBody

private Map<String, Object> getShopInitInfo() {
	Map<String, Object> modelMap = new HashMap<String, Object>();
	List<ShopCategory> shopCategoryList = new ArrayList<ShopCategory>();
	List<Area> areaList = new ArrayList<Area>();
	try {
		shopCategoryList = shopCategoryService.getShopCategoryList(new ShopCategory());
		areaList = areaService.getAreaList();
		modelMap.put("shopCategoryList", shopCategoryList);
		modelMap.put("areaList", areaList);
		modelMap.put("success", true);
	} catch (Exception e) {
		modelMap.put("success", false);
		modelMap.put("errMsg", e.getMessage());
	}
	return modelMap;
}

@RequestMapping(value = "/registershop", method = RequestMethod.POST)
@ResponseBody

private Map<String, Object> registerShop(HttpServletRequest request) {
	Map<String, Object> modelMap = new HashMap<String, Object>();
	if (!CodeUtil.checkVerifyCode(request)) {
		modelMap.put("success", false);
		modelMap.put("errMsg", "输入了错误的验证码");
		return modelMap;
	}
	// 1.接收并转化相应的参数,包括店铺信息以及图片信息
	String shopStr = HttpServletRequestUtil.getString(request, "ShpoStr");
	ObjectMapper mapper = new ObjectMapper();
	Shop shop = null;
	try {
		shop = mapper.readValue(shopStr, Shop.class);
	} catch (Exception e) {
		modelMap.put("success", false);
		modelMap.put("errMsg", e.getMessage());
		return modelMap;
	}
	CommonsMultipartFile shopImg = null;
	CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
			request.getSession().getServletContext());
	if (commonsMultipartResolver.isMultipart(request)) {
		MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
		shopImg = (CommonsMultipartFile) multipartHttpServletRequest.getFile("shopImg");
	} else {
		modelMap.put("success", false);
		modelMap.put("errMsg", "上传图片不能为空");
		return modelMap;
		// 图片信息是必须的
	}
	// 2.注册店铺
	if (shop != null && shopImg != null) {
		PersonInfo owner = new PersonInfo();
		// Session TODO
		owner.setUserId(1L);
		shop.setOwner(owner);
		// File shopImgFile = new File(PathUtil.getImgBasePath() +
		// ImageUtil.getRandomFileName());
		ShopExecution se;
		try {
			se = shopService.addShop(shop, shopImg.getInputStream(), shopImg.getOriginalFilename());
			if (se.getState() == ShopStateEnum.CHECK.getState()) {
				modelMap.put("success", true);
			} else {
				modelMap.put("success", false);
				modelMap.put("errMsg", se.getStateInfo());
			}
		} catch (ShopOperationException e) {
			modelMap.put("success", false);
			modelMap.put("errMsg", e.getMessage());
		} catch (IOException e) {
			modelMap.put("success", false);
			modelMap.put("errMsg", e.getMessage());
		}
		return modelMap;
	} else {
		modelMap.put("success", false);
		modelMap.put("errMsg", "请输入店铺信息");
		return modelMap;
	}
	// 3.返回结果
}

/*
 * private static void inputStreamToFile( InputStream ins, File file) {
 * FileOutputStream os = null; try { os = new FileOutputStream(file); int
 * bytesRead = 0; byte[] buffer = new byte[1024]; while ((bytesRead =
 * ins.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } } catch
 * (Exception e) { throw new RuntimeException("调用inputStreamToFile产生异常:" +
 * e.getMessage()); } finally { try { if (os != null) { os.close(); } if ( ins
 * != null) { ins.close(); } } catch (IOException e) { throw new
 * RuntimeException("inputStreamToFile关闭IO产生异常:" + e.getMessage()); } } }
 */

}

写回答

3回答

慕勒2534496

提问者

2019-05-14

已解决,registerShop方法里有一个字符串拼错了:[笑哭]//img.mukewang.com/szimg/5cda876a000156a409040277.jpg

1
0

翔仔

2019-05-14

报错的应该不是这个问题,需要同学看看是前端没有获取到还是后端没有获取到?确认一下。

然后也可以跟这个成品里面的shoperation.js源码对比一下

链接: https://pan.baidu.com/s/1M_NURPWwb8ZQvhQ6ULH0Cw 提取码: htjn 复制这段内容后打开百度网盘手机App,操作更方便哦

修改完成后,记得清空页面缓存试试

0
0

慕勒2534496

提问者

2019-05-13

报错://img.mukewang.com/szimg/5cd982630001958105850115.jpg

0
0

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5131 学习 · 8152 问题

查看课程