How to remove the root node name from the json returned by Spring MVC, mvcjson
The configuration view in spring xml is as follows:
<property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"> </bean> </list> </property>
The returned result is:
{"commonAjaxResponse":{"code":1,"errorCode":null,"errorMessage":null,"data":{"key":"123"}}}
Here, commonAjaxResponse is not what we want.
Note that the API description of the attribute extractValueFromSingleKeyModel of MappingJackson2JsonView can be set to true.
<property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"> <property name="extractValueFromSingleKeyModel" value="true" /> </bean> </list> </property>
Solution:
{"code":1,"errorCode":null,"errorMessage":null,"data":{"key":"123"}}