If the configuration view in spring xml is as follows
<property name="defaultViews"><list><bean></bean></list></property>
Then the return result will be:
{"commonAjaxResponse":{"code":1,"errorCode":null,"errorMessage":null,"data":{"key":"123"}}} Among them, commonAjaxResponse is not what we want.
Note the API description of the extractValueFromSingleKeyModel property of MappingJackson2JsonView, you can set this property to true to solve it.
<property name="defaultViews"><list><beanclass="org.springframework.web.servlet.view.json.MappingJackson2JsonView"><property name="extractValueFromSingleKeyModel" value="true" /></bean></list></property>
Get it done:
{"code":1,"errorCode":null,"errorMessage":null,"data":{"key":"123"}}The above is the method of removing the root node name from the JSON returned by Spring MVC. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!