ajax 前台页面不显示,后台也不报错

GAOCHENGCHAO 2019-03-09 11:20:53
前台页面不显示,后台也不报错, No matching resource found - returning 404
Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling




@RequestMapping(value="/Add")
@ResponseBody
public ReturnResult add(HttpServletRequest request, HttpServletResponse response) throws Exception {
String id = request.getParameter("entityId");
String quantityStr = request.getParameter("quantity");
Integer quantity = 1;
ReturnResult result=new ReturnResult();
System.out.println("员工id"+id);
if (!EmptyUtils.isEmpty(quantityStr))
quantity = Integer.parseInt(quantityStr);
//查询出商品
Product product = productService.getProductById(Integer.valueOf(id));
if(product.getStock()<quantity){
return result.returnFail("商品数量不足");
}
//获取购物车ss
ShoppingCart cart = getCartFromSession(request);
//往购物车放置商品
result=cart.addItem(product, quantity); //放入商品ID 和 商品数量
if(result.getStatus()==Constants.ReturnResult.SUCCESS){
cart.setSum((EmptyUtils.isEmpty(cart.getSum()) ? 0.0 : cart.getSum()) + (product.getPrice() * quantity * 1.0));
}
return result;
}















function addCartByParam(entityId,quantity){
//添加到购物车
$.ajax({
url: contextPath + "/Cart/Add",
method: "post",
data: {
entityId: entityId,
quantity: quantity
},
dataType="json",
success: function (result) {
var result = eval("(" + jsonStr + ")");
//状态判断
if (result.status == 1) {
showMessage("操作成功");
refreshCart();
}else{
showMessage(result.message);
}
},
error:function(result){
alert:("发生错误!");
}
} )
}
...全文
418 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GAOCHENGCHAO 2019-03-11
  • 打赏
  • 举报
回复
@Controller @RequestMapping(value="/Cart") @RequestMapping(value="/Add") @ResponseBody public Object add(HttpServletRequest request, HttpServletResponse response) throws Exception { String json; HttpSession session = request.getSession(); ReturnResult result = new ReturnResult(); String id = request.getParameter("entityId"); String quantityStr = request.getParameter("quantity"); Integer quantity = 1; if (!EmptyUtils.isEmpty(quantityStr)) quantity = Integer.parseInt(quantityStr); //查询出商品 Product product = productService.getProductById(Integer.valueOf(id)); if(product.getStock()<quantity){ return result.returnFail("商品数量不足"); } //获取购物车 ShoppingCart cart = getCartFromSession(request); //往购物车放置商品 result=cart.addItem(product, quantity); if(result.getStatus()==Constants.ReturnResult.SUCCESS){ cart.setSum((EmptyUtils.isEmpty(cart.getSum()) ? 0.0 : cart.getSum()) + (product.getPrice() * quantity * 1.0)); } //1.将Bean转换为Json格式 json = JSONObject.toJSONString(result); return json; }
GAOCHENGCHAO 2019-03-10
  • 打赏
  • 举报
回复

) DispatcherServlet with name 'spring' processing GET request for [/GCC_YMW/Cart/add]
No mapping found for HTTP request with URI [/GCC_YMW/Cart/add] in DispatcherServlet with name 'spring'
winterDown 2019-03-10
  • 打赏
  • 举报
回复
看看你的类上有没有
@Controller
@RequestMapping("/Cart");
然后在浏览器f12看下网络,ajax传给后台的数据请求对不对
missingMuMu 2019-03-10
  • 打赏
  • 举报
回复
ajax的url没匹配到spring的url,修改RequestMapping

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧