1.编写简单的mybatis架构后,运行显示出现错误:Type interface com.dao.UserDao is not known to the MapperRegistry.

2.添加mybatis-config.xml中<mappers>代码

    <mappers>
        <mapper resource="com/dao/UserMapper.xml"/>
    </mappers>

出现错误:Could not find resource com/dao/UserMapper.xml

3.在pom.xml中</project>前添加一下代码,之后刷新maven 运行成功

<!--    设置资源目录,使其可以读取dao下xml文件-->
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐