GBase8s Spring Boot MyBatis 操作示例
本文将创建一个简单的 Spring Boot 项目结构,并演示如何使用 Mybatis 进行GBase 8s 数据库的数据
处理工作(插入,选择,更新和删除),以及分页显示。
MyBatis + XML方式
本文我们会使用 mybatis-spring-boot-starter 自动化配置 MyBatis 主要配置。同时,在 XML 中编写相
应的 SQL 操作。
1.1 引入依赖
在 pom.xml 文件中,引入相关依赖。
4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.5.RELEASE GBase8s-Spring-Boot-MyBatis-Demo GBase8s-Spring-Boot-MyBatis-Demo GBase8s-Spring-Boot-MyBatis-Demo 1.8 org.springframework.boot spring-boot-starter-jdbc com.gbasedbt gbasedbtjdbc 1.0.0 system ${project.basedir}/lib/ifxjdbc.jar org.mybatis.spring.boot 1234567891011121314151617181920212223242526272829303132333435363738
1.2 Application
创建 Application.java 类,配置 @MapperScan 注解,扫描对应 Mapper 接口所在的包路径。代码如
下:
cn.gbase.8s.demo.mybatis.mapper 包路径下,就是我们 Mapper 接口所在的包路径。
1.3 应用配置文件
在 resources 目录下,创建 application.yml 配置文件。配置如下:
mybatis-spring-boot-starter 2.1.1 org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin true 394041424344454647484950515253545