Content negotiation in Spring MVC

后端 未结 2 902
说谎
说谎 2021-01-06 14:27

I am writing a RESTful web application with Spring 3, and part of my application needs to process the data according to the requested media type.

@RequestMap         


        
2条回答
  •  攒了一身酷
    2021-01-06 15:02

    The @RequestMapping annotation has an optional headers attribute that allows you to narrow the mapping to requests with specific headers, e.g. to match XML:

    @RequestMapping(value = "/something", headers = "content-type=application/xml")
    

    You can also specify multiple variants:

    @RequestMapping(value = "/something", headers = [{"content-type=application/xml","content-type=text/xml"}])
    

    It's a little bit low level, but does the job.

提交回复
热议问题