Mybatis通用mapper.xml和mybatis-config.xml模板

Mybatis通用mapper.xml和mybatis-config.xml模板

1.步骤

1.点击Settings
在这里插入图片描述
2.找到Editor编辑中的File and Code Templates
在这里插入图片描述
3.点击+号
在这里插入图片描述
4.输入文件名和文件类型(xml),把模板代码复制进去点击apply应用即可
在这里插入图片描述

2.模板代码

1.mapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace是对应接口的全类名-->
<mapper namespace="">
</mapper>

2.mybatis-config.xml(mybatis的主配置文件)

<?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>
<!--    别名-->
    <typeAliases>
        <package name=""/>
    </typeAliases>
<!--    指定其他mapper文件所在位置-->
    <mappers>
<!--        package使用要求:1.接口和对应mapper在同一目录
                           2.接口和对应mapper的名称一致-->
        <package name=""/>
    </mappers>
</configuration>

猜你喜欢

转载自blog.csdn.net/TheWayForDream/article/details/120609315