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"
這是足夠的,或者我需要設置的頭了。謝謝