spring-boot集成mybatis-plus 报错
报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.mapper.UserMapper.selectList
一、导入依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>3.4.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
</dependencies>
二、创建数据表
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`name` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名',
`age` int NULL DEFAULT NULL COMMENT '年龄',
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
`version` int NULL DEFAULT 1 COMMENT '乐观锁',
`deleted` int NULL DEFAULT 0 COMMENT '逻辑删除',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (1, 'kuangshen222', 18, '24736743@qq.com', 3, 0, NULL, '2021-06-09 10:48:25');
INSERT INTO `user` VALUES (2, 'Jack', 20, 'test2@baomidou.com', 1, 0, NULL, NULL);
INSERT INTO `user` VALUES (3, 'Tom', 28, 'test3@baomidou.com', 1, 0, NULL, NULL);
INSERT INTO `user` VALUES (4, 'Sandy', 21, 'test4@baomidou.com', 1, 0, NULL, NULL);
INSERT INTO `user` VALUES (5, 'Billie', 24, 'test5@baomidou.com', 1, 0, NULL, NULL);
INSERT INTO `user` VALUES (6, '王五1', 22, 'yxb0429@hotmail.com', 1, 0, NULL, '2021-06-08 18:00:31');
INSERT INTO `user` VALUES (7, '李四', 23, 'yxb0429@hotmail.com', 1, 0, '2021-06-08 18:01:24', '2021-06-08 18:01:24');
INSERT INTO `user` VALUES (1402195650429149186, '张三', 20, 'yxb0429@hotmail.com', 1, 0, NULL, NULL);
INSERT INTO `user` VALUES (1402195650429149187, '李四', 20, 'yxb0429@hotmail.com', 1, 0, NULL, NULL);
SET FOREIGN_KEY_CHECKS = 1;
三、User
@Data
public class User {
private Long id;
private String name;
private int age;
private String email;
}
四、UserMapper
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
五、application.yml
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/testMyBatisPlus?characterEncoding=UTF-8&useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai
username: root
password: 123456
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
六、添加 @MapperScan
@SpringBootApplication
@MapperScan("com.example.mapper")
public class MybatisplusApplication {
public static void main(String[] args) {
SpringApplication.run(MybatisplusApplication.class, args);
}
}
@SpringBootTest
class MybatisplusApplicationTests {
@Autowired()
private UserMapper userMapper;
@Test
public void testSelect() {
System.out.println(("----- selectAll method test ------"));
List<User> userList = userMapper.selectList(null);
for (User user : userList) {
System.out.println(user);
}
}
}

浙公网安备 33010602011771号