【发布时间】:2012-04-07 17:51:17
【问题描述】:
我的控制器是这样的
@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"
这是否足够或者我也需要设置标题。谢谢
【问题讨论】:
标签: spring spring-mvc spring-roo