1.创建工程导入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
2.配置数据源
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 下面为自定义SQL需要配置的
mybatis-plus.type-aliases-package=com.peng.pojo
mybatis-plus.mapper-locations=classpath:mapper/*.xml
3.创建实体类对应数据库
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/575ebff722b8985f8e34a3173f97d214.png)
4.编写接口继承BaseMapper<此处泛型为实体类
>
package com.peng.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peng.pojo.User;
import org.springframework.stereotype.Component;
@Component
public interface UserMapper extends BaseMapper<User> {
}
5.结束,直接在测试类测试看看
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class MybatisplusApplicationTests {
@Autowired
private UserMapper userMapper;
@Test
void contextLoads() {
List<User> userList = userMapper.selectList(null);
System.out.println(userList);
}
}
结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cc38e8d9a9b1698adc65c68f0685dc2e.png)
问题
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6cc5fb990f59a0b4a59e8da6495d023d.png)