当我测试该方法时,我得到了这个错误
(not found): com.timmy.mapper.UserMapper.selectAllUsers
所以我尝试解决这个问题,但我没有看到任何错误我检查了映射器命名空间、映射器方法名称、@mapperScan 路径和我扫描映射器的路径,但它似乎都是正确的
项目结构项目
结构
application.yml 设置
mybatis-plus:
mapper-locations: classpath:com/timmy/mapper/*.xml
type-aliases-package: com.timmy.domain
global-config:
db-config:
table-prefix: "tb_"
id-type: auto
configuration:
auto-mapping-behavior: full
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mp?
serverTimezone=GMT%2b8&useUnicode=true&characterEncoding=UTF-8
username: root
password: timmy072869
用户映射器.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">
<mapper namespace="com.timmy.mapper.UserMapper">
<resultMap id="userMap" type="user">
<id column="id" property="id" jdbcType="INTEGER"/>
</resultMap>
<select id="selectAllUsers" resultMap="userMap">
select * from tb_user
</select>
</mapper>
用户映射器.java
package com.Timmy. mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.timmy.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import java.util.List;
@Component
public interface UserMapper extends BaseMapper<User> {
List<User> selectAllUsers();
}
pom.xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
应用程序.java
@MapperScan("com.timmy.mapper")
@SpringBootApplication(scanBasePackages = "com.timmy.*")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new
MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new
PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
我检查了很多次,但没有发现任何问题,我错过了什么吗?请