@responsebody to return string instead of view



I want my string method to return value. The below code returns a view(jsp). In the code "line" stores the product details.I want the method to return this value. Could someone show me how to do it.



@RequestMapping(value="addtocart{id}")
@ResponseBody
public String addToCart(@PathVariable("id") int id, @ModelAttribute("cart") Cart cart)
{
Product product = productService.getProductById(id);
if (product != null) {
CartLine line = new CartLine();
line.setProduct(product);
line.setQuantity(1);
return "viewcart";
}


xml config



<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="prefixJson" value="false"/>
<property name="supportedMediaTypes" value="application/json"/>
</bean>

No comments:

Post a Comment