0
我的控制器是这样我是否需要设置响应头春位指示
@RequestMapping(value ="/getTaggedProducts", method = RequestMethod.GET)
@ResponseBody
public String getProductsTagged(@RequestParam("questionnaireId")Long questionnaireId){
Map<String, Object> response = new HashMap<String, Object>();
try{
Questionnaire questionnaireProduct = Questionnaire.findQuestionnaire(questionnaireId);
Organisation userOrg = getUserAffiliation();
if (questionnaireProduct == null) throw new QuestionnaireBuilderException("Questionnaire '" + questionnaireId + "'does not exist");
if (!questionnaireProduct.isEditable()) throw new QuestionnaireBuilderException("You cannot edit a questionnaire which has been assigned");
Set<Product> productCategories = questionnaireProduct.getProducts();
List<Long> productIds = new ArrayList<Long>();
for(Product p: productCategories){
productIds.add(p.getId());
}
LOG.debug("Product Categories successfully added to questionnaire");
response.put("message", "success");
response.put("products", productIds);
} catch (QuestionnaireBuilderException e) {
LOG.debug(e.getMessage(), e);
response.put("message", e.getMessage());
} catch (Exception e) {
LOG.error("Unhandled Exception: " + e.getMessage(), e);
response.put("message", "Unhandled Exception");
}
return new JSONSerializer().exclude("*.class").deepSerialize(response);
}
不会设置响应头引起任何问题。我知道如何从这个问题设置的响应头 - In Spring MVC, how can I set the mime type header when using @ResponseBody 在我的Ajax调用我指定
datatype: "json"
这是足够的,或者我需要设置的头了。谢谢