mybatisgenerator生成器报错Invalid bound statement (not found): com.example.mapper.*.selectByExample

文章介绍了如何配置MyBatisGenerator在SpringBoot项目中使用,包括在pom.xml和mybatis-generator-config.xml中的设置,以及遇到的XML文件未被加载的问题。解决方法是在application.yml中指定mapper文件位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用myabtisgenerator配置:

pom.xml

       <!--mybatis 逆向生成-->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>${mybatis-generator.version}</version>
                <configuration>
                    <overwrite>true</overwrite>    <!-- 是否覆盖 -->
                    <configurationFile>src/main/resources/mybatis-generator-config.xml</configurationFile>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.27</version>
                    </dependency>
                </dependencies>
            </plugin>

mybatis-generator-config.xml

<?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE generatorConfiguration
                PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
                "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
<context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">

    <!-- 自动检查关键字,为关键字增加反引号 -->
    <property name="autoDelimitKeywords" value="true"/>
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>

    <!--覆盖生成XML文件-->
    <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
    <!-- 生成的实体类添加toString()方法 -->
    <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>

    <!-- 不生成注释 -->
    <!--        <commentGenerator>-->
    <!--            <property name="suppressAllComments" value="true"/>-->
    <!--        </commentGenerator>-->

    <!---数据库连接信息-->
    <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                    connectionURL="jdbc:mysql://localhost:3306/db"
                    userId="root"
                    password="123456">
    </jdbcConnection>

    <!--自动 domain[Bean]类的位置 -->
    <javaModelGenerator targetProject="src\main\java"
                        targetPackage="com.example.bean.pojo"/>

    <!--自动 mapper xml的位置 -->
    <sqlMapGenerator targetProject="src\main\resources"
                     targetPackage="mapper"/>

    <!--自动 mapper类[接口]的位置 -->
    <javaClientGenerator targetProject="src\main\java"
                         targetPackage="com.example.bean.mapper"
                         type="XMLMAPPER"/>

    <table tableName="student" domainObjectName="Student"></table>
</context>
</generatorConfiguration>

 运行后报错

 原因是找不到sql查询语句所对应的xml文件;

默认情况下springboot会加载resource下mapper中的xml文件,如果出现如上问题可以进行如下配置:

再application.yml中手动配置springboot加载静态文件:

 

mybatis:
  mapper-locations: classpath:mapper/*.xml

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值