Web API 分享補充
===
## Vincent
###### tags: `SpringBoot`
---
## join table
- inner join(等值連接)
- outer join
- left join (左側table為主)
- right join(右側table為主)
- full join(列出所有關連table資料)
----
## join table 的建議
- 輸出另建model
- 獨立撰寫mapper
---
## web api 的參數型式(get)
- 前端
- restful style(/1/2/xx)
- query parameter(?a=1&b=1&c=xx)
- 後端
- @PathVariable
- @RequestParam(required)
----
## web api 的參數型式(post)
- 前端
- json
- x-www-form-urlencoded
- multipart(formdata)
- 後端
- 與get相同
- @RequestBody
- @RequestPart
---
## call external web api
- 外部資料交換
---
## mybatis 其他應用
- skip row first row
- sum, avg, min, max
---
## 其他
- spring doc
- 多場景的application.properties
- CORS
----
## spring doc
- [spring doc官網](https://springdoc.org)
```
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.12</version>
</dependency>
```
----
## spring doc
- 在Controller的mapping加上annotation
```
@Tag(name = "讀取合約主檔一(restful style)")
@Operation(summary = "", description = "查詢合約資料內容")
```
- 關閉spring doc
```
springdoc.api-docs.enabled=false
springdoc.swagger-ui.enabled=false
```
---
## 套用不同的專案設定檔(因應不同場景)
- application-xxx.properties
- 在application.properties加入
```
spring.profiles.active=xxx
```
---
## CORS
- [參考資料](https://blog.huli.tw/2021/02/19/cors-guide-1/)

----
## CORS
```
@CrossOrigin(origins = "*") allowed all domain
@CrossOrigin(origins = {"http://www.example1.com","http://www.example2.com"}) allowed for multiple domains
```
---
# END
{"metaMigratedAt":"2023-06-16T14:38:33.794Z","metaMigratedFrom":"Content","title":"Web API 分享補充","breaks":true,"contributors":"[{\"id\":\"4190ad5d-3e7c-40f0-84e4-9a81138fcfbf\",\"add\":1617,\"del\":17}]","description":"inner join(等值連接)"}