This topic describes how to configure dependencies and configuration files for a MyBatis connection.
Configure dependencies
<dependency>
<groupId>com.alipay.oceanbase</groupId>
<artifactId>oceanbase-client</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.4</version>
</dependency>
Configuration files
mybatis-config.xml
The following example shows the content of the configuration file:
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.alipay.oceanbase.jdbc.Driver"/>
<property name="url" value="jdbc:oceanbase://10.100.xxx.xxx:18817/test?useUnicode=true&characterEncoding=utf-8&useServerPrepStmts=false&useCursorFetch=true"/>
<property name="username" value="admin@mysql"/>
<property name="password" value="******"/>
</dataSource>
</environment>
</environments>
<!--Register the mapper (the address of mapper.xml)-->
<mappers>
<mapper resource="com/test/UserMapper.xml"></mapper>
</mappers>
</configuration>
mapper.xml
The following example shows the content of the configuration file:
<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--Make sure that the namespace field is set to the mapper API.-->
<mapper namespace="com.test.UserMapper">
<select id="selectUser" resultType="com.test.User" fetchSize="40000">
select * from user;
</select>
<delete id="delete" >
delete from user;
</delete>
</mapper>