AJAX和SpringMVC交互

前端之家收集整理的这篇文章主要介绍了AJAX和SpringMVC交互前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

AJAX

利用jquery

<script> function loadXMLDoc() { var params = {}; params.sellerId = "1111111111111111111111111111111111"; $.ajax({ type: "POST",url: "http://localhost:8080/v1/seller/order/new",data: JSON.stringify(params),contentType: "application/json; charset=utf-8",//此处不能省略 dataType: 'json',success: function (data) { if (data.code != 200) { alert("失败") } else { } },error: function () { alert("numerror"); } }); } function myFunction() { loadXMLDoc(); } </script>

SPRING

/** * 创建订单 */
    @RequestMapping(value = "/order/new",method = RequestMethod.POST)
    public void newOrder(@RequestBody SellerOrderRequest sellerOrderRequest) {
        logger.info("Create new seller order : {}",sellerOrderRequest.getSellerId());
    }
public class SellerOrderRequest {

    private String sellerId;

    public String getSellerId() {
        return sellerId;
    }

    public void setSellerId(String sellerId) {
        this.sellerId = sellerId;
    }
}
原文链接:https://www.f2er.com/springmvc/161008.html

猜你在找的SpringMVC相关文章