• york
    2019-09-09
    老师,对于Chapter 6/springbucks(Waiter Service)中的代码有个疑问:
    在CoffeeController.class中根据id来查询咖啡订单的示例代码是这样的:
    @GetMapping("/{id}")
    public CoffeeOrder getOrder(@PathVariable("id") Long id) {
         CoffeeOrder order = orderService.get(id);
         log.info("Get Order: {}", order);
         return order;
    }
    如果我把上述代码改成:
    @GetMapping("/{id}")
    public CoffeeOrder getOrder(@PathVariable("id") Long id) {
         return orderService.get(id);
    }

    为何这样改之后,客户端查询到的结果是null?
    展开

    作者回复: 因为Hibernate用这个方法会返回一个代理对象,没有使用时它就会是null,你可以换个方法获取对象,所以我log了一下……我看到好几个留言讲到了null的事情,我录制时应该提醒一下的,抱歉。

    
     3
  • kai楷
    2019-04-10
    老师,一般WebClient和RestTemplate会用在什么地方

    作者回复: 在你需要访问下游HTTP接口时就会用到,就不要想着自己直接使用HttpClient这样的方式了,有RestTemplate这样更方便的方式可以选。如果是异步的,那就用WebClient。

    
     1
  • WL
    2019-03-25
    老师请问一下如果配置了WebApplicationType.NONE, 那程序跑一下就结束了, 如果想让程序一直跑, 而这个程序又不是一个web服务的后台, 那应该怎么配置?

    作者回复: 给你一个听起来特不靠谱的答案……主线程里写个死循环吧

     1
     1
  • AaronYu
    2019-11-30
    老师,在 orderCoffee 方法里面
    NewOrderRequest orderRequest = NewOrderRequest.builder()
                    .customer("Li Lei")
                    .items(Arrays.asList("capuccino"))
                    .build();
    RequestEntity<NewOrderRequest> request = RequestEntity
                    .post(UriComponentsBuilder.fromUriString("http://localhost:8080/order/").build().toUri())
                    .body(orderRequest);
            ResponseEntity<CoffeeOrder> responseEntity = restTemplate.exchange(request, CoffeeOrder.class);

    我们向 http://localhost:8080/order/ uri post 了一个 orderRequest,但是这个 http://localhost:8080/order/ 我们在 waiter-service 里面需要的是 (@PostMapping(value = "/",consumes = MediaType.APPLICATION_JSON_VALUE) )application/json 类型的,springboot 是怎么自动帮我们上传 json 的数据的啊?
    展开

    作者回复: 当有多种可用序列化方式时,在内部有个顺序的,通常情况下,都会优先使用JacksonJSON进行序列化。

    
    
  • 灰灰灰
    2019-07-17
    启动customer-service时执行到readMenu()中ResponseEntity<List<Coffee>> list = restTemplate
                    .exchange("http://localhost:8080/coffee/", HttpMethod.GET, null, ptr);报错了,提示Current token (START_OBJECT) not numeric, can not use numeric value accessors。
    
    
  • 白衣
    2019-05-04
    老师好,reactive和非reactive不是异步和同步吧,应该是非阻塞和阻塞吧,我打个比方,Nio和bio,就是非阻塞和阻塞io,而不是异步和同步的区别,我知道我这么类比对吗?

    作者回复: 你的表述是正确的,可能我在说的时候没能正确清楚地表达出来吧

    
    
  • 码农Kevin亮
    2019-03-29
    老师,我对所谓的“reactive方式访问http资源”这个概念不太明白。也就是说,我对“http的访问方式都有哪些”与“reactive方式具体指什么”这两个问题没有概念,请指点一下,谢谢

    作者回复: Reactive和非Reactive也就异步和同步的区别,用WebClient和RestTemplate

    
    
我们在线,来聊聊吧