学无先后,达者为师

网站首页 前端文档 正文

mapper配置xml映射错误 Invalid bound statement (not found): com.springboot_jsp_shiro.dao.UserMapper.save

作者:TAIKI_daiji 更新时间: 2024-03-28 前端文档

mapper配置踩坑记录

我新建了一个SpringBoot工程,并打算用xml编写mapper

这是我的文件结构
请添加图片描述
显然,我的UserMapper.xml的路径是resources/mapper/UserMapper.xml

我的UserMapper的路径是com.springboot_jsp_shiro/dao/UserMapper

这是我最开始的配置

server.port=8888
server.servlet.context-path=/shiro
spring.application.name=shiro

spring.freemarker.prefix=/
spring.mvc.view.suffix=.jsp

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/shiro?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123456

mybatis.type-aliases-package=com.springboot_jsp_shiro.entity 	#实体类映射
mybatis.mapper-locations=classpath:com/mapper/*.xml 	# xml mapper映射

我搭了一个完整的简单业务流程,启动工程测试程序的可用性

但是在调用mapper的位置出现了这个报错
请添加图片描述
Invalid bound statement (not found): com.springboot_jsp_shiro.dao.UserMapper.save
明显的xml mapper映射错误

随即去检查了xml和mapper接口的方法名

<?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">
<mapper namespace="com.springboot_jsp_shiro.dao.UserMapper">

    <insert id="save" parameterType="User" useGeneratedKeys="true" keyProperty="id">
        insert into t_user value (#{id},#{username},#{password},#{salt});
    </insert>

</mapper>
@Mapper
public interface UserMapper {
    public int save(User user);
}

发现方法名是对得上的,没有问题

然后只能去检查配置文件,发现在这行出现了错误

mybatis.mapper-locations=classpath:com/mapper/*.xml 	# xml mapper映射

但是我xml mapper的路径压根没有com/ !!请添加图片描述
遂修正,把路径上的com/去掉了

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

成功跑通!

原文链接:https://blog.csdn.net/qq_39354855/article/details/137039657

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新