0

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 ?

2
  • 1
    if you dont want to return anything in a post method you should add @ResponseStatus(value = HttpStatus.OK) to the method. i think what happend here is that spring is trying to find a view based on the request url. adding the above annotation should force spring to just send an empty response with the specified status code. Commented Apr 20, 2017 at 14:56
  • @TommySchmidt : Thank you so much for your well explanation! Commented Apr 20, 2017 at 16:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.