Spring MVC @ResponseBody return a List

后端 未结 7 1469
说谎
说谎 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:34

    @ResponseBody will automatically encode the object you return to appropriate formats based on the Accept header of the request and the presence of JSON and/or XML libraries in the classpath.

    It can be easier/safer to define your own object to wrap the list in though rather than returning the list directly - as that gives you more control over the encoding and also allows you to potentially add other data in the future.

提交回复
热议问题