首页 > 其他分享 >Mybatis配置文件

Mybatis配置文件

时间:2023-03-06 12:13:00浏览次数:32  
标签:配置文件 自定义 TypeHandler setting BaseTypeHandler Mybatis

1.结构

配置的属性顺序不能错

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!--    属性
            1.外部文件
            2.子元素-->
    <properties resource="db.properties">
        <property name="" value=""/>
    </properties>

    <settings>
        <setting name="jdbcTypeForNull" value="NULL"/>
    </settings>

<!--    类型别名-->
    <typeAliases>
        <typeAlias type="Article" alias="article"></typeAlias>
<!--        通过包形式设置别名 首字母小写作为别名-->
        <package name="com.xxx.entity"/>
    </typeAliases>

<!--    类型处理器-->
/**
 * 自定义类型转化器
 * 1.实现TypeHandler
 * 2.继承BaseTypeHandler
 */
    <typeHandlers>
        <typeHandler handler="MyHandler" javaType="String" jdbcType="VARCHAR"></typeHandler>
<!--        自动扫包注册-->
        <package name="com.xxx.handler"/>
    </typeHandlers>

<!--    对象工厂
        自定义ObjectFactory
        实现ObjectFactory接口
        继承DefaultObjectFactory
-->
    <objectFactory type="com.xxx.EntityObjectFactory"></objectFactory>

    <!--    mybatis运行环境
            不同环境可以操作不同数据库-->
    <environments default="development">
        <environment id="development">
            <!--事务管理器
                    JDBC: 直接使用JDBC的提交和回滚设置,依赖从数据源获取的连接来管理事务作用域
                    MANAGED: 不提交或回滚一个连接,让容器来管理事务整个生命周期-->
            <transactionManager type="JDBC"></transactionManager>
            <!--数据源
                    UNPOOLED: 非连接池类型,每次请求时才打开关闭连接
                    POOLED: 连接池
                    JNDI: 在EJB或应用服务器之类的容器使用
                -->
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <!-- 注册Mapper-->
        <mapper resource="mapper/ArticleMapper.xml"></mapper>
        <mapper resource="mapper/StudentMapper.xml"></mapper>
        <mapper resource="mapper/StuClassMapper.xml"></mapper>
        <package name="com.xxx.mapper"/>
    </mappers>
    
</configuration>

2.setting配置


标签:配置文件,自定义,TypeHandler,setting,BaseTypeHandler,Mybatis
From: https://www.cnblogs.com/lwx11111/p/17183272.html

相关文章

  • springmvc配置文件
    <?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"......
  • spring找不到配置文件applicationContext.xml
    问题描述:报错信息为Causedby:java.io.FileNotFoundException:classpathresource[applicationContext.xml]cannotbeopenedbecauseitdoesnotexisttarget目......
  • MyBatis连接Oracle数据库的细节错误总结
    错误一错误提示org.apache.ibatis.exceptions.PersistenceException:###Errorupdatingdatabase.Cause:java.sql.SQLSyntaxErrorException:ORA-00911:无效字符......
  • Mybatis 和 Mybatis Plus 的区别(面试)
    MybatisPlusMybatis-Plus是一个Mybatis的增强工具,只是在Mybatis的基础上做了增强却不做改变,MyBatis-Plus支持所有Mybatis原生的特性,所以引入Mybatis-Plus不会对现有的Myb......
  • mybatis分页插件的使用
    引入依赖<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.2.0</version></depend......
  • mybatis中遇到的一个小问题【There is no result map named java.lang.Integer in thi
    在使用mybatis的时候,配置一个查询总数的SQL语句,发现提示下面的问题:Thereisnoresultmapnamedjava.lang.IntegerinthisSqlMap百思不得骑姐<selectid="UPP_COUPON_T......
  • springmvc+mybatis+velocity配置
    首先说明,在java的web框架中,最难的一个步骤,就是设置配置文件,配置文件复杂繁多,而且特别容易配置错误,经过不懈努力,一步步配置好了。1、文件目录本工程是eclipse+maven的web......
  • mybatis缓存
    一级缓存  二级缓存   二级缓存相关配置  mybatis缓存查询的顺序 ......
  • java-spring 通过配置文件获取bean
    1、druid.properties#mysql连接参数jdbc.driver-class-name=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/wangdb?useUnicode=true&characterEncodi......
  • mybatis动态标签——sql标签
    mapper接口EmpgetEmpById(@Param("id")Integerid); mapper.xml<!--sql片段:可以记录一段sql,在需要用的地方使用include标签进行引用--><......