d112113114 2022-06-04 15:47
浏览 29
已结题

mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found):

mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found): com.keke.mapper.EmpMapper.Select5


//查询10号部门中工种为MANAGER和20部门中工种为CLERK的员工的信息。
    @GetMapping("Select5")
    public Result Select5(){
        List<Emp> emps=empService.Select5();
        System.out.println(emps);
        return Result.success(emps);
    }
//-----------------------------------------------------
用注解方式是正常的  把注解方式注释掉 试试xml写法
 //@Select("select * from emp where job='MANAGER' and deptno=10 union select * from emp where job='CLERK' and deptno=20")
    List<Emp> Select5();
//-------------------------------------------------------------
 <mapper namespace="com.keke.mapper.EmpMapper">
    <resultMap id="BaseResultMap" type="com.keke.domain.Emp">
        <!--@mbg.generated-->
        <!--@Table emp-->
        <id column="EMPNO" jdbcType="INTEGER" property="empno"/>
        <result column="ENAME" jdbcType="VARCHAR" property="ename"/>
        <result column="JOB" jdbcType="VARCHAR" property="job"/>
        <result column="MGR" jdbcType="INTEGER" property="mgr"/>
        <result column="HIREDATE" jdbcType="DATE" property="hiredate"/>
        <result column="SAL" jdbcType="DECIMAL" property="sal"/>
        <result column="COMM" jdbcType="DECIMAL" property="comm"/>
        <result column="DEPTNO" jdbcType="INTEGER" property="deptno"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO
    </sql>
    <select id="Select5" resultMap="BaseResultMap" >
    select <include refid="Base_Column_List"></include> from emp where JOB='MANAGER' and DEPTNO=10
    union
    select <include refid="Base_Column_List"></include> from emp where JOB='CLERK' and DEPTNO=20
    </select>
</mapper>

直接报错
Invalid bound statement (not found): com.keke.mapper.EmpMapper.Select5

感觉就是扫描不到 xml文件 (不知道是不是)
但是在配置文件却配置了
##配置数据源
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: 123456
max-active: 10 #最大活跃连接数
min-idle: 5 #小小的活跃连接数
validation-query: select 'x' #验证连接是否可用的sql
#监控页
stat-view-servlet:
enabled: true #开启数据源监控
login-username: keke
login-password: keke
allow: #允许连接的IP --白名单
deny: #不允许连接的IP --黑名单
url-pattern: /druid/*
#开启mybatis的配置
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #配置sql控制台输出

在启动类上也配置了
@MapperScan(basePackages = {"com.keke.mapper"})

网上的常规方法都是试过了!有没有人指点下

  • 写回答

1条回答 默认 最新

  • d112113114 2022-06-05 03:10
    关注

    问题已经解决,一个低级的错误,xml的包名要和配置中的包名一致

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月13日
  • 已采纳回答 6月5日
  • 修改了问题 6月4日
  • 创建了问题 6月4日

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题