请理解英语是不够的。
在这段代码中,我没有使用 mybatis config xml。
创建 SqlSessionFactory 代码)
DataSource dataSource = new PooledDataSource(driver, url, username, password);
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("development", transactionFactory, dataSource);
Configuration configuration = new Configuration(environment);
//Maybe load mybatis-mapper.xml
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
mybatis-config.xml)
<?xml version="1.0" encoding="UTF-8" ?>
<!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="org.mariadb.jdbc.Driver" />
<property name="url" value="jdbc:mariadb://***.***.***.***:*****/*****" />
<property name="username" value="********" />
<property name="password" value="********" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="/mybatis/mapper/testMapper.xml" />
</mappers>
</configuration>
在Create SqlSessionFactory Code中,我成功设置了DataSource、TransactionManager、Enviroment。
但是我不知道如何在像这个xml代码这样的java代码中加载mybatis mapper xml。
<mappers>
<mapper resource="/mybatis/mapper/testMapper.xml" />
</mappers>
我想在没有 mybatis-config.xml 的情况下加载 mybatis mapper xml
但我不想使用映射器接口和 @Select 之类的注释。