I have created a lush service with SpringMVC and have a bunch of tutorials and it worked fine. Now, in some cases the application should be application / JSON or REFRESH, and in other cases with normal view resolver and text / html (.jsp). - I thought ContentNegotiatingViewResolver would apply the best in this case (is?).
Now my question: Which view / servlet / * should I use to display JSON (REST results) directly? This is my servlet.xml:
& lt; Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: context = "http: //www.springframework Org / schema / context" xmlns: xsi = "http://www.w3.org / 2001 / XMLSchema-instance "xsi: schema location =" http://www.springframework.org/schema/beans http: // www .springframework.org / schema / beans / spring-beans-3.0 .xsd http : //www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "& gt; & Lt; Reference: component-scan base-package = "com.atrioom" /> & Lt; Bean square = "org.springframework.web.servlet.view.ContentNegotiatingViewResolver" & gt; & Lt; Property Name = "Media Type" & gt; & Lt; Map & gt; & Lt; Entry key = "JSON" value = "App / JSON" /> & Lt; Entry key = "html" value = "text / html" /> & Lt; / Map & gt; & Lt; / Property & gt; & Lt; Property Name = "Viewrollers" & gt; & Lt; List & gt; & Lt; Bean square = "org.springframework.web.servlet.view.BeanNameViewResolver" /> & Lt; Bean class = "org.springframework.web.servlet.view.UrlBasedViewResolver" & gt; & Lt; Property Name = "View Class" Value = "org.springframework.web.servlet.view.JstlView" /> & Lt; Property Name = "Prefix" Value = "/ Web-NF / JSP /" /> & Lt; Property name = "suffix" value = ".jsp" /> & Lt; / Bean & gt; & Lt; / List & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt ;! - Bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" & gt; & Lt; Property Name = "Prefix" & gt; & Lt; Price & gt; / Web-INF / jsp / & lt; / Pricing & gt; & Lt; / Property & gt; & Lt; Property name = "suffix" & gt; & Lt; Price & gt; .jsp & lt; / Pricing & gt; & Lt; / Property & gt; & Lt; / Bean - & gt;
Now for each request, the servlet appears to display a .jsp
file. That's for text / html
and application / json
. The way I want it to behave, it's a view (JSP) when called text / html
, and when a direct Jason output is called application / json
Gives the service I have done this job when I created only one service, no jsp file was needed, the app returned the JSON-formatted data directly.
I do not know how to tell the conversation what to do in the JSN case. Do I have a special REST Resolver? Can someone leave the light, please?
Type
You must configure MappingJackson 2 HTTP Message Conferencing
in your visual resolver property
API Consulting
Comments
Post a Comment