我正在試用Spring Boot,我正面臨着一個小問題。我無法在@RestController中使用@PathVariable。這裏是我的控制器 -@PathVariable不能與@RestController一起工作
package com.harshil.controller;
import org.springframework.web.bind.annotation.*;
@RestController
public class UserController {
@RequestMapping(name = "/user/{id}/", method = RequestMethod.GET)
public User getUser(@PathVariable("id") int id) {
return generateUser(id);
}
}
這是我打電話是終點 - http://localhost:8080/user/1/
在我以前的春天(不啓動)的項目,我用@PathVariable在@Controller和它工作得很好。我無法弄清楚我可能做錯了什麼。想法?
什麼是「不工作」的意思?像例外,http響應等... – Blank