可以从这里查看myabtis的tag列表,截至到当前2021-09-07 11:40:48
最新版本为3.5.7
,如下图:
如下是基于maven引入3.3.1
版本:
<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.3.1</version> </dependency>
一般名称定义为mybatis-config.xml
,当然也可以自定义,定义属性,别名,环境,插件,类型处理器,对象工厂,mapper映射信息等,如下是一个可能配置:
<?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> <properties resource="mybatis/mybatisOuter.properties"> <property name="projectName" value="dongshidaddy-learn-java"/> </properties> <settings> <setting name="mapUnderscoreToCamelCase" value="true"/> <setting name="logPrefix" value="dongshidaddy--^^--"/> <setting name="cacheEnabled" value="true"/> <!-- <setting name="lazyLoadTriggerMethods" value="getClass,getManyagce,c"/>--> <setting name="aggressiveLazyLoading" value="false"/> </settings> <typeAliases> <!--<typeAlias type="yudaosourcecode.mybatis.TestMybatis" alias="TestMybatis"/>--> <package name="yudaosourcecode.mybatis"/> </typeAliases> <typeHandlers> <!--<typeHandler handler="yudaosourcecode.mybatis.typehandler.EnumAndIntTypeHandler" javaType="yudaosourcecode.mybatis.MyEnum" jdbcType="INTEGER"/>--> <typeHandler handler="yudaosourcecode.mybatis.typehandler.EnumAndIntTypeHandler" javaType="yudaosourcecode.mybatis.MyEnum"/> <!--<package name="yudaosourcecode.mybatis.typehandler"/>--> </typeHandlers> <!-- <objectFactory type="yudaosourcecode.mybatis.objectfactory.MyObjectFactory"> <property name="name" value="zhangsan"/> <property name="age" value="90"/> </objectFactory> --> <!--<objectWrapperFactory type="yudaosourcecode.mybatis.objectwrapperfactory.MyObjectWrapperFactory"/>--> <!-- <plugins> <plugin interceptor="yudaosourcecode.mybatis.interceptor.MyInterceptor"> <property name="xxx" value="yyyy"/> <property name="aaaa" value="bbbb"/> </plugin> </plugins> --> <plugins> <plugin interceptor="yudaosourcecode.mybatis.interceptor.MyPagingPlugin"/> </plugins> <!-- 配置mybatis自动转换为驼峰式命名 --> <!-- 环境,可以配置多个,default:指定采用哪个环境 --> <environments default="test"> <!-- id:唯一标识 --> <environment id="test"> <!-- 事务管理器,JDBC类型的事务管理器 --> <transactionManager type="JDBC" > <property name="" value=""/> </transactionManager> <!-- 数据源,池类型的数据源 --> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3366/ssmdemo" /> <property name="username" value="root" /> <property name="password" value="root" /> </dataSource> </environment> </environments> <!--数据库厂商标示 --> <databaseIdProvider type="DB_VENDOR"> <property name="Oracle" value="oracle"/> <property name="MySQL" value="mysql"/> </databaseIdProvider> <mappers> <!--<mapper resource="mybatis/mapper/TestMyBatisMapper.xml"/> <mapper resource="mybatis/mapper/TestTypehandlerMapper.xml"/>--> <!--<mapper resource="mybatis/mapper/TestTypehandlerMapper.xml"/>--> <!--<package name="yudaosourcecode.mybatis.mapper"/>--> <mapper resource="yudaosourcecode/mybatis/mapper/TestResultmapAndParametermapMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/MyMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestMyBatisMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestTypehandlerMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/UserDaoMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/UserMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestExtendAndAutoMappingMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestResultmapConstructorMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestResultmapCollectionOneMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestResultmapCollectionManyMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestMapperSqlMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestLanguageDriverMapper.xml"/> <mapper resource="yudaosourcecode/mybatis/mapper/TestSelectKeyMapper.xml"/> <!--<mapper resource="yudaosourcecode/mybatis/mapper/TestSelectKeyMapperHuohuo.xml"/>--> </mappers> </configuration>
TODO