gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:22:08 25 4
gpt4 key购买 nike

为了将值传递给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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com