企业级API网关
API網關就是用來代替控制器層 Controller,使用API網關直接調用Service層
在Service層加 @APIMapping
http://localhost:8080/api?method=XX¶m=XX
?
API store :? 存儲所有帶有APIMapping 的類
存儲的對像為 APIRunnable,
apiName, targetMethod, target,? 放到一個Map里
?
Controller
1. 接收HTTP參數
2. 把HTTP參數字符串封裝成java 對象
3. 調用服務方法
4, 將返回結果進行Json序列化封裝
?
API網關要做的事情:
1. 驗證系統參數合法性
例如: apiName 或者 method 為空,則拋一個異常
2. 驗證業務參數合法性
3. 業務參數轉換成java 對象
4. 調用相對應的Service類的方法
5. 拿到返回結果,封裝成json
6. 異常統一處理,封裝異常,返回
?
?
執行順序:? PIGatewayServlet===>API handle ===> store
?
String name=applicationConext.getBeanDefinitionNames
Class<?> type= applicationContext.getType(name)
?
?
?
總結