Spring 4 @RequestMapping — consumes vs headers?

前端 未结 2 2079
星月不相逢
星月不相逢 2021-02-03 10:31

I\'m learning how to build RESTful web services using Spring 4, and one thing I\'m not clear on is in @RequestMapping. I\'ve seen examples where one uses headers = \"Acce

2条回答
  •  故里飘歌
    2021-02-03 11:11

    As the javadoc of HeadersRequestCondition (which handles the value provided in the headers attribute of a @RequestMapping annotation) states

    Expressions passed to the constructor with header names 'Accept' or 'Content-Type' are ignored. See ConsumesRequestCondition and ProducesRequestCondition for those.

    So don't use those headers in headers. Use the produces and consumes attributes for Accept and Content-Type.

    As to how to use them, the documentation gives examples: for consumes and for produces.

提交回复
热议问题