2017-04-20 84 views
0

将值传递给java我已经使用AngularJs中的post方法到我的java代码,它可以很好地执行我需要的操作,并且我的代码如下所示:Thymeleaf错误解析模板 - 使用方法= RequestMethod.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 

我没有为/架模板,我不想把它作为我只是想把价值传递给我的班级。我该如何解决这个问题?

+1

如果你不想在post方法中返回任何东西,你应该给方法添加'@ResponseStatus(value = HttpStatus.OK)'。我想这里发生的事情是,春天试图根据请求url找到一个视图。添加上面的注释应该强制spring发送一个带有指定状态码的空响应。 –

+0

@TommySchmidt:非常感谢您的好解释! – Majico

回答

1

正如@Tommy Schmidt解释得非常好,如果你不想在post方法中返回任何东西,你应该在该方法中添加@ResponseStatus(value = HttpStatus.OK)

相关问题