0.官方文档
1.创建工程导入依赖
<!--mybatis-plus--> <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.创建实体类对应数据库
4.编写接口继承BaseMapper<此处泛型为实体类>
package com.peng.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.peng.pojo.User; import org.springframework.stereotype.Component; @Component //或者@Repository 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); } }
结果
问题