MyBatis הוא פריימוורק של התמדה עם תמיכה ב-SQL בהתאמה אישית ובמיפויים מתקדמים. MyBatis מבטל את רוב קוד ה-JDBC ואת ההגדרה הידנית של פרמטרים ואחזור תוצאות באפליקציה.
הגדרת MyBatis למסדי נתונים של Spanner GoogleSQL-dialect
אפשר לשלב מסדי נתונים של Spanner GoogleSQL עם MyBatis ו-Spring Boot באמצעות מנהל ההתקן Spanner JDBC.
תלויות
בפרויקט, מוסיפים יחסי תלות של Apache Maven ל-MyBatis, ל-Spring Boot ול-Spanner JDBC driver.
<dependencies>
<!-- MyBatis and Spring Boot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.dynamic-sql</groupId>
<artifactId>mybatis-dynamic-sql</artifactId>
</dependency>
<!-- Spanner JDBC driver -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-jdbc</artifactId>
</dependency>
<dependencies>
הגדרת מקור נתונים
מגדירים את application.properties כך שישתמש במנהל ההתקן Spanner JDBC ויתחבר למסד נתונים של Spanner GoogleSQL-dialect.
spanner.project=my-project
spanner.instance=my-instance
spanner.database=mybatis-sample
spring.datasource.driver-class-name=com.google.cloud.spanner.jdbc.JdbcDriver
spring.datasource.url=jdbc:cloudspanner:/projects/${spanner.project}/instances/${spanner.instance}/databases/${spanner.database}
אפליקציה לדוגמה מלאה
כדי לנסות את השילוב הזה עם אפליקציה לדוגמה, אפשר לעיין במאמר Spring Data MyBatis Sample Application with Spanner GoogleSQL.
המאמרים הבאים
- MyBatis
- מידע נוסף על MyBatis ו-Spring Boot
- מידע נוסף על Spring Boot
- מדווחים על בעיה ב-GitHub כדי לדווח על באג או לשאול שאלה לגבי מנהל ההתקן של Spanner JDBC.