老师救...
救命,加了验证码没有显示。。
还有想问一下,最下面图片的js路径,为啥只需要退一级目录就能获取到了?参照我这里的目录结构,shop_operation.html退一级目录不是到与html文件夹同级目录下么?求解,谢谢
57
收起
正在回答
14回答
同学你好!
老师使用你的代码是可以的。你可以直接在浏览器输入地址测试一下
比如:http://localhost:8080/o2o/kaptcha?66
你第一次加载页面时,图片可以出来吗?你是点击的时候出现的问题吗?如果是:你刷新一下页面重新测试一下。可能访问加载比较慢导致的
注意:是否有大小写不一致问题
祝学习愉快~
qq_粽翎_0
2020-02-24 11:32:00
@Controller("shopManagementController") @RequestMapping("/shop_admin") public class ShopManagementController { @Autowired private ShopService shopService; @Autowired private ShopCategoryService shopCategoryService; @Autowired private AreaService areaService; @RequestMapping("/shop_init") @ResponseBody private Map<String, Object> initShop() { Map<String, Object> modelMap = null; List<Area> areaList = null; List<ShopCategory> shopCategoryList = null; try { modelMap = new HashMap<>(); areaList = areaService.getAllArea(); shopCategoryList = shopCategoryService.getShopCategory(new ShopCategory()); modelMap.put("areaList",areaList); modelMap.put("shopCategoryList",shopCategoryList); modelMap.put("success",true); } catch (Exception e) { modelMap.put("success",false); modelMap.put("msg", e.getMessage()); } return modelMap; } @RequestMapping("/shop_register") private Map<String, Object> registerShop(HttpServletRequest request) { Map<String, Object> modelMap = new HashMap<>(); //先处理验证码 if (!VerifyCodeUtil.checkVerifyCode(request)) { modelMap.put("success", false); modelMap.put("msg", "验证码错误!"); return modelMap; } //1.接收并转换相应参数,包括店铺信息和图片信息 String shopStr = HttpServletRequestUtil.getString(request, "shopStr"); ObjectMapper mapper = new ObjectMapper(); Shop shop = null; try { shop = mapper.readValue(shopStr, Shop.class); //将页面读取到的参数转换为shop实体类 } catch (Exception e) { modelMap.put("success", false); modelMap.put("msg", e.getMessage()); return modelMap; } CommonsMultipartFile shopImg = null; //定义文件上传解析器,去解析request里面的文件信息 CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver( request.getSession().getServletContext()); //判断是否有上传的文件流 if (commonsMultipartResolver.isMultipart(request)) { MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request; //通过指定参数获取文件流,并进行转换成spring能够处理的CommonsMultipartFile类型 shopImg = (CommonsMultipartFile) multipartHttpServletRequest.getFile("shopImg"); } else { modelMap.put("msg", "上传图片不能为空"); return modelMap; } //2.注册店铺 if (shopImg != null && shop != null) { User user = (User)request.getSession().getAttribute("user"); shop.setUser(user); ShopExecution shopExecution = null; try { shopExecution = shopService.addShop(shopImg.getInputStream(), shopImg.getOriginalFilename(), shop); if (shopExecution.getStatus() == ShopStatusEnum.CHECK.getStatus()) { modelMap.put("success", true); } else { modelMap.put("success", false); modelMap.put("msg", shopExecution.getStatusInfo()); } } catch (IOException e) { modelMap.put("success", false); modelMap.put("msg", e.getMessage()); return modelMap; } return modelMap; } else { modelMap.put("success", false); modelMap.put("msg", "请输入店铺信息"); return modelMap; } } }
qq_粽翎_0
2020-02-24 10:10:43
$(function () { var initUrl = '/o2o/shop_admin/shop_init'; var registerShopUrl = '/o2o/shop_admin/shop_register'; getShopInit(); function getShopInit() { $.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); $('#shop-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 : $('#shop-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 = $('#shop-kaptcha').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.msg); } $('#kaptcha_img').click(); } }); }); });
qq_粽翎_0
2020-02-23 17:35:20
好了,新问题出来了,图片加载不出来,求救~
<!--验证码相关配置--> <servlet> <servlet-name>kaptcha</servlet-name> <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class> <!--是否有边框--> <init-param> <param-name>kaptcha.border</param-name> <param-value>no</param-value> </init-param> <!--图片宽度--> <init-param> <param-name>kaptcha.image.width</param-name> <param-value>135</param-value> </init-param> <!--图片高度--> <init-param> <param-name>kaptcha.image.height</param-name> <param-value>50</param-value> </init-param> <!--字体--> <init-param> <param-name>kaptcha.textproducer.font.names</param-name> <param-value>Arial</param-value> </init-param> <!--字体颜色--> <init-param> <param-name>kaptcha.textproducer.font.color</param-name> <param-value>red</param-value> </init-param> <!--字体大小--> <init-param> <param-name>kaptcha.textproducer.font.size</param-name> <param-value>43</param-value> </init-param> <!--干扰线颜色--> <init-param> <param-name>kaptcha.noise.color</param-name> <param-value>black</param-value> </init-param> <!--使用哪些字符生成验证码--> <init-param> <param-name>kaptcha.textproducer.char.string</param-name> <param-value>ACDGHLINRTXM23579</param-value> </init-param> <!--验证码字符个数--> <init-param> <param-name>kaptcha.textproducer.char.length</param-name> <param-value>4</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>kaptcha</servlet-name> <url-pattern>/kaptcha</url-pattern> </servlet-mapping>
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星