Spring MVC @ResponseBody return a List

后端 未结 7 1466
说谎
说谎 2021-02-10 03:22

We would like to create a \"WebService\" which return a list of specific objects. And we would like to call this webservice from another java program by apache http clients libr

7条回答
  •  情书的邮戳
    2021-02-10 03:50

    The @ResponseBody annotation tells Spring that we will be returning data in the response body rather than rendering a JSP.

    When the @ResponseBody annotation is used, Spring will return the data in a format that is acceptable to the client. That is, if the client request has a header to accept json and Jackson-Mapper is present in the classpath, then Spring will try to serialize the return value to JSON. If the request header indicates XML as acceptable (accept=application/xml) and Jaxb is in the classpath and the return type is annotated with Jaxb annotation, Spring will try to marshall the return value to XML.

提交回复
热议问题