Spring MVC configuration Returns JSON requires two important beans
Contentnegotiatingviewresolver
Mappingjackson2jsonview
Specific look at the code
<BeanID= "Contentnegotiationmanager"class= "Org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> < Propertyname= "MediaTypes"> <value>html=text/html Json=application/json xml=application/xml </value> </ Property> < Propertyname= "Defaultcontenttype"value= "text/html"/> </Bean> <!--contentnegotiatingviewresolver View parser allows you to configure multiple return values - <Beanclass= "Org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> < Propertyname= "Order"value= "0"/> < Propertyname= "Contentnegotiationmanager"ref= "Contentnegotiationmanager"/> < Propertyname= "Viewresolvers"> <List> <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/> < Propertyname= "prefix"value= "/web-inf/jsp/"/> < Propertyname= "suffix"value= ". jsp"/> </Bean> </List> </ Property> < Propertyname= "Defaultviews"> <List> <Beanclass= "Org.springframework.web.servlet.view.json.MappingJackson2JsonView"> < Propertyname= "Extractvaluefromsinglekeymodel"value= "true" /> </Bean> <Beanclass= "Org.springframework.web.servlet.view.xml.MarshallingView"> < Propertyname= "Marshaller"> <Beanclass= "Org.springframework.oxm.xstream.XStreamMarshaller" /> </ Property> </Bean> </List> </ Property> </Bean> <BeanID= "Multipartresolver"class= "Org.springframework.web.multipart.support.StandardServletMultipartResolver"/>
Return JSON to the browser directly with HTTP