---
# System prepended metadata

title: Java Spring 學習雜紀
tags: [Java, Spring]

---

# Java Spring 學習雜紀

## @GetMapping & @RequestMapping

* [@RequestMapping](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html)
    * @GetMapping
    * @PostMapping
    * @PutMapping
    * @DeleteMapping
    * @PatchMapping


1. @GetMapping/@RequestMapping 實現URL處理：
```
// @RequestMapping ：
@RequestMapping(value = /get/{id}", method = RequestMethod.GET)

// 簡化為：
@GetMapping("/get/{id}")
```
2. @RequestMapping > @GetMapping 不能互相交換。@GetMapping的位置只能在class之內，而@RequestMapping在內外也可以

## @ComponentScan
定義掃描的路徑從中找出標識了需要裝配的類自動裝配到spring的bean容器中
[doc](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html)

###### tags: `Java` `Spring`