I am having an issue trying when trying to return HTML to my Spring MVC controller.
It looks like this:
@RequestMapping(value = QUESTION_GROUP_CREATE_URL, method = RequestMethod.POST)
public
@ResponseBody
String createQuestionGroup(@RequestBody JsonQuestionGroup questionGroup, HttpServletResponse response) {
// questionGroup - this comes OK.
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
return "<div></div>";
}
My Spring config:
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false"/>
<property name="favorParameter" value="true"/>
<property name="mediaTypes">
<value>
json=application/json
xml=application/xml
html=application/html
</value>
</property>
</bean>
I am seeing firebug that response is coming like: {"String":"<div></div>"}
how can I tell this method to send me plain HTML as the response?
Of course. This is not a hybris feature.
Rest api returns html instead of json if api route does not exists.
Introduction. In Spring Boot, the controller class is responsible for processing incoming REST API requests, preparing a model, and returning the view to be rendered as a response.
Change your Spring config like this: html=text/html
and add produces = MediaType.TEXT_HTML_VALUE
to your's @RequestMapping
annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With