为了将值传递给Java,我使用了AngularJs的post方法到我的Java代码中,并且可以很好地完成我需要的工作,并且我的代码如下所示:
@RequestMapping(value="/shelf", method=RequestMethod.POST, consumes="application/json")
public void getSelectedShelf(@RequestBody String shelf) throws JSONException {
logger.debug("Start uploading the files...");
logger.debug(shelf.toString());
JSONObject json;
try {
json = new JSONObject(shelf);
} catch (JSONException e) {
throw new IllegalArgumentException("Invalid JSON Payload: " + shelf, e);
}
selectedShelf= json.getLong("shelf");
logger.debug(selectedShelf+"");
logger.info("Json Payload = " + json);
}
,但是在我的java方法的末尾,我看到以下错误:
"org.thymeleaf.exceptions.TemplateInputException: Error resolving template "shelf", template might not exist or might not be accessible by any of the configured Template Resolvers
我没有用于/ shelf的模板,也不想拥有它,因为我只想将值传递给我的班级。我该如何解决这个问题?
最佳答案
正如@Tommy Schmidt很好地解释的那样,如果您不想在post方法中返回任何内容,则应在该方法中添加@ResponseStatus(value = HttpStatus.OK)
。