我写一个给前台的删除的接口可是报五百的错误说不支持get请求方式怎么处理呢?又打很知道吗

@DeleteMapping("/del/{id}")
void del(@PathVariable int id){
   orderRepository.delete(id);
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

前台

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function showOrder(userid){

$(".order-info").html("<img class='loadgif' src='images/loading.gif'/>");

$.ajax({

url:"http://127.0.0.1:8081/order/list/" + userid, 

type:"get",

success:function(data){

console.info("订单信息",data);

var orderHtml = "";

$.each(data, function(index,order) {

var productHtml = "";

$.each(order.plist, function(i,product) {

productHtml += "<tr><td><a href='##'><img src=" 

+ product.img + " alt='product'></a></td><td style='max-width: 200px;'><span>" + product.name

+ " </span></td><td>¥ " + product.sell 

+ " </td><td><span>数量: " + order.nlist[i]

+ " </span></td></tr> "

});

orderHtml += "<div class='order-detail' data-no='" + order.orderNo + "' data-username='" + order.user.username + "' data-day='" + order.createDate + "'><div class='order-top'><strong>订单号:</strong><span>" + order.orderNo

+ "</span><strong>购买者:</strong><span>" + order.user.username 

+ "</span><strong>时间:</strong><span>" + order.createDate 

+ "</span><input type='button' class='cancel-order btn btn-xs' value='取消订单' /><i class='openBtn'><span class='glyphicon glyphicon-chevron-up' aria-hidden='true'></span></i></div><table class='table productTable'>" 

+ productHtml 

+ "</table><div class='order-buttom text-right'><strong>总价:</strong><span>¥&nbsp;" + order.total 

+ "</span><strong>佣金:</strong><span>¥&nbsp;" + order.profitsStr 

+ "</span></div></div>"

});

$(".order-info").html(orderHtml);

},

error:function(){

$(".order-info").html("加载失败!!!").css({"font-size":"20px","color":"red"}).addClass("text-center");

}

});

};


鬼鬼qiang
浏览 2241回答 2
2回答

leiqjl

type:"get"前端Ajax发送的是get请求,而你后端@DeleteMapping对应的是delete请求,你把type改成delete试试

褪去浮尘

deleteMapping改成requestMapping
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java