【发布时间】:2020-03-15 20:18:46
【问题描述】:
使用Maven 创建一个简单的Spring Boot 应用程序。我用RestController 注释给出了一个值,但它不起作用。如果我不使用RestController 的值,它可以工作。我想知道,为什么它不起作用以及@RestController 中的值有什么用?
http://localhost:9090/app/hello 这给出了错误
http://localhost:9090/hello 这工作正常
@RestController("/app")"/app"这个值在@RestController注解里面的作用是什么?
P.S:我知道,我可以在 ScraperResource 类上使用@RequestMapping("/app")。
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
@RestController("/app")
public class ScraperResource {
@GetMapping("hello")
public String testController() {
return "Hello";
}
}
application.properties
server.port=9090
【问题讨论】:
标签: java spring spring-boot rest