14.

【Spring】@PathVariableアノテーションとは

編集

本稿はSpringFrameworkの@PathVariableについて説明します。

 

@PathVariableとは

@PathVariableとはURLに含まれた文字列をパラメータとして受け取るためのアノテーションです。

以下、簡単なサンプルです。

@RequestMapping(path = "/{num}", method = RequestMethod.GET)

public String index(@PathVariable int num) {

return Integer.toString(num * 2);

}

 

以下のリクエストをすることで「」の結果を得ることができます。

http://localhost:8080/2

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. @After
  2. @Autowired
  3. @Bean
  4. @Before
  5. @Column
  6. @Component
  7. @Configuration
  8. @Controller
  9. @Data
  10. @Entity
  11. @GeneratedValue
  12. @Id
  13. @Modifying
  14. @PathVariable
  15. @PropertySource
  16. @Repository
  17. @RequestBody
  18. @RequestMapping
  19. @ResponseBody
  20. @RestController
  21. @Service
  22. @SpringBootApplication
  23. @Table
  24. @Transactional
  25. @Value