我正在寻找在Spring中使用@QueryParam的简单示例。 我的想法是要有一个链接,看起来像这样,它将获得id值,运行我的java类并显示返回的String。我的问题是找不到返回值。
http://localhost:8080/recipesinfo?id=274596
发生意外错误(类型=内部服务器错误,状态= 500)。 评估SpringEL表达式的异常:“ recipesinfo.step”(模板:“ recipesinfo_result”-第12行,第22列)
DemoApplication.java
RecipesInfo repinfo = new RecipesInfo();
@RequestMapping("/recipesinfo")
public String getInfo (@RequestParam("id") int id) throws IOException {
repinfo.execute(id);
return "recipesinfo_result";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(DemoApplication.class, args);
}
recipesinfo_result.html
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Recipes</title>
</head>
<body>
<p class="title"><a th:text="${recipesinfo.step}"></a><br></body>
</html>
RecipesInfo.java
public String execute(int id) throws IOException {
//using id in a Http request here and returning String step (the problem isn't here)
return step;
}
我已经在可以正常工作的Web服务中完成了与此类似的操作,但是该操作只是返回JSON。