mark mybatis annotation driven
mybatis annotaion方式並不像spring,需要指定annotation-driven來啟用annotaion特性。
mybatis預設支援annotation,參考MapperRegistry#addMapper
/**
* MapperRegistry Configuration實現annotaion mapper註冊的幫助類
**/
public <T> void addMapper(Class<T> type) {
if (type.isInterface()) {
try {
MapperAnnotationBuilder parser = new MapperAnnotationBuilder(config, type);
parser.parse();
} finally {
//...
}
}
}
接下來就是對Method物件的parse,解析出完整的mapped-statement 配置
public void parse() {
// Class級別解析
parseCache();
parseCacheRef();
Method[] methods = type.getMethods();
// Method級別解析
for (Method method : methods) {
try {
// 根據Annotation解析完整的MappedStatement資訊
parseStatement(method);
} catch (IncompleteElementException e) {
// 加入待處理佇列
configuration.addIncompleteMethod(new MethodResolver(this, method));
}
}
// 再次嘗試解析 IncompleteMethod
parsePendingMethods();
}
最後,將解析完的mapped-statement 歸入configuration
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
// ......
MappedStatement statement = statementBuilder.build();
configuration.addMappedStatement(statement);
附:mybatis Mapper XML 解析順序
- 迴圈指定的mapperLocations,建立對應XMLMapperBuilder
- 解析mapper node,addMappedStatement
- guess xml namespace(Class),引入Annotation處理流程
- 建立MapperAnnotationBuilder
- 解析 Class.method annotation,addMappedStatement
- ……
相關文章
- <mvc:annotation-driven/>使用介紹MVC
- Mybatis原始碼分析(二)XML的解析和Annotation的支援MyBatis原始碼XML
- Annotation
- 【mybatis annotation】資料層框架應用--Mybatis(二) 基於註解實現資料的CRUDMyBatis框架
- Java建立AnnotationJava
- Annotation註解
- The Mark by Stone and Flower Made
- python pytest.markPython
- 標記類 mark
- Java —— 註解(Annotation)Java
- @EnableAsync annotation metadata was not injected
- 貧血模型 - DDD - The Domain Driven Design模型AI
- 使用Domain-Driven建立Hypermedia APIAIAPI
- java-Annotation註解Java
- Java之註解(Annotation)Java
- Spring常用Annotation簡介Spring
- PathVariable annotation was empty on param 0
- ch11_enum_and_annotation
- pytest-mark 引數化
- [BJDCTF2020]Mark loves catTF2
- Java註解(Annotation)詳解Java
- Transmit Value by Customized Annotation in AOP InterceptionMITZed
- Spring Boot Configuration Annotation Processor not configuredSpring Boot
- annotation之context:annotation-config與 context:component-scan的區別與聯絡Context
- java: 無法訪問org.mybatis.spring.annotation.MapperScan、類檔案具有錯誤的版本 61.0, 應為 52.0JavaMyBatisSpringAPP
- Android APT(Annotation Processing Tool) 實踐AndroidAPT
- Android 註解系列之Annotation(二)Android
- ANNOVAR region-based annotation-上篇
- Java進階(一)Annotation(註解)Java
- 113. 路徑總和 II mark
- GeoLayout: Geometry Driven Room Layout Estimation Based on Depth Maps of PlanesOOM
- Java 註解 (Annotation)淺入深出Java
- 使用Django annotation,提升django查詢效能Django
- Java註解(Annotation):請不要小看我!Java
- 大年初一mark一下
- Openlayer add mark及新增hover效果例項
- 2021-2-28 Mark-Java Interview SimpleJavaView
- Razavi - RF Microelectronics的筆記 - Current-Driven Passive Mixer筆記
- 論文解讀(AGCN)《 Attention-driven Graph Clustering Network》GC