Search code examples
javapostspring-bootthymeleaf

Thymeleaf Error resolving template - using method=RequestMethod.POST


To pass a value to java I have used post method from AngularJs to my java code and it works just fine to do what i needed and my code is as the followoing :

@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);

 }

, but at the end of my java method, I see the following error:

"org.thymeleaf.exceptions.TemplateInputException: Error resolving template "shelf", template might not exist or might not be accessible by any of the configured Template Resolvers

I don't have a template for /shelf and I don't want to have it as I just want to pass a value to my class. How can I resolve this problem ?


Solution

  • As @Tommy Schmidt has explained very well, if you don't want to return anything in a post method you should add @ResponseStatus(value = HttpStatus.OK) to the method.