java - Thymeleaf 解析模板时出错 - 使用 method=RequestMethod.POST

标签 java post spring-boot thymeleaf

为了将值传递给java,我使用了从AngularJs到我的java代码的post方法,它可以很好地完成我需要的操作,我的代码如下:

@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) 添加到该方法中。

关于java - Thymeleaf 解析模板时出错 - 使用 method=RequestMethod.POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43519063/

相关文章:

java - 使用 Java 以编程方式确定 2 个图像看起来是否相同

ruby-on-rails - 删除 Rails 中 facebook graph api 发布的帖子上的 "via APP_NAME"

html - 单选按钮+数组元素

PHP curl : CURLOPT_URL, CURLOPT_POST 和 CURLOPT_POSTFIELDS

java - Avro - java.io.IOException : Not a data file

maven - 为什么 Spring Boot 应用程序需要 hikariCP?

java - 如果你在一个 jar 中运行 java,你能在运行时告诉你吗?

java - 在 Java swing 中获取组合框值

java - taskScheduler 池的奇怪行为

spring - Spring Webflux 安全中的角色层次结构