[英]Implementation method not being called from Rest Controller using Spring
[英]Spring Controller method being called again with the own method result
这是我的 controller:
@Controller
@RequestMapping("/area")
public class AreaController {
@RequestMapping("/{id}")
public String getPage(@PathVariable("id") int id){
return "asd3333";
}
}
这就是我访问 http://localhost:8080/area/1 时得到的结果:
我测试了这个随机返回只是为了显示正在发生的事情......首先使用来自请求的@PathVariable = 1调用该方法,然后在此之后再次调用该方法是否结果,在这种情况下,它试图通过@PathVariable = "asd3333" 。
我不知道发生了什么,请帮忙
听起来确实很奇怪。 我将从一个问题开始
@RequestMapping("/{id}")
public String getPage(@PathVariable("id") int id){
return "asd3333";
}
是否需要为所有方法类型(Get、Post、Delete...)调用此方法。 如果没有尝试限制特定的方法调用。
前任
@RequestMapping(value = "/{id}", method = POST)
明白了。
还要将此添加到方法中,因为您返回一个简单的字符串
@RequestMapping("/{id}")
@ResponseBody
public String getPage(@PathVariable("id") int id)
Also if you don't plan to use this API as a web MVC application but instead as a rest API backend switch from @Controller to @RestController.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.