喜爱Java语言 2023-07-16 17:27 采纳率: 100%
浏览 16
已结题

关于#java#的问题,请各位专家解答!


package com.itheima.shop;

import com.itheima.shop.pojo.TradeOrder;
import org.junit.Test;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;

/**
 * @author shkstart
 * @create 2023-07-14 20:09
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ShopOrderWebApplication.class)
public class OrderWebTest {
    @Autowired
    private RestTemplate restTemplate;

    @Value("${shop.order.baseURI}")
    private String baseURI;

    @Value("${shop.order.confirm}")
    private String confirmOrderPath;

    @Test
    public void confirmOrder() {
        Long couponId = 345988230098857984L;
        Long goodsId = 345959443973935104L;
        Long userId = 345963634385633280L;

        TradeOrder order = new TradeOrder();

        order.setGoodsId(goodsId);
        order.setUserId(userId);
        order.setCouponId(couponId);
        order.setAddress("北京");
        order.setGoodsNumber(1);
        order.setGoodsPrice(new BigDecimal(1000));
        order.setShippingFee(BigDecimal.ZERO);
        order.setOrderAmount(new BigDecimal(1000));
        order.setMoneyPaid(new BigDecimal(100));
        Result result = restTemplate.postForEntity(baseURI+ confirmOrderPath,order, Result.class).getBody();
        System.out.println(result);
    }

}

package com.itheima.shop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.shop.api.IOrderService;
import com.itheima.shop.entity.Result;
import com.itheima.shop.pojo.TradeOrder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create 2023-07-09 18:09
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private IOrderService orderService;

    @RequestMapping("/confirm")
    public Result confirmOrder(@RequestBody TradeOrder order) {
        return orderService.confirOrder(order);
    }
}

img

  • 写回答

3条回答 默认 最新

  • 二九筒 2023-07-16 17:37
    关注

    你请求地址前面为啥要加个 order-web? 直接就是order开头啊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月24日
  • 已采纳回答 7月16日
  • 创建了问题 7月16日

悬赏问题

  • ¥15 Mplus跑出来的数据只有原数据的一半
  • ¥15 vue项目添加全局处理解决一些开发问题
  • ¥40 微信小程序前后端交互
  • ¥15 linux安装依赖问题
  • ¥50 数据预处理(大量数据)
  • ¥15 多设备数据融合可视化显示控制
  • ¥15 公众号关键词自动回复超链接
  • ¥18 help me! 希望大家来看看 吉~
  • ¥15 C++显示超限兔子集结
  • ¥15 sql server 2012的下载出错