1、首先正常建立一个springboot项目,同时要记得勾选mysql driven
2、手动添加SpringBoot整合MyBatis-Plus的坐标,可以通过mvnrepository获取
也就是https://mvnrepository.com/该网站
1)在搜索框输入 mybatis plus
点击进入
点击进入(选取自己所需)
2)将方块所选放入pom.xml
3、定义数据层接口与映射配置,继承BaseMapper
@Mapper
public interface UserDao extends BaseMapper<User> {
}
4、其他同SpringBoot整合MyBatis
(略)
①:创建新模块,选择Spring初始化,并配置模块相关基础信息 ②:选择当前模块需要使用的技术集(MyBatis、MySQL) ③:设置数据源参数 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ssm_db username: root password: root 注意事项 SpringBoot版本低于2.4.3(不含),Mysql驱动版本大于8.0时,需要在url连接串中配置时区 jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC 或在MySQL数据库端配置时区解决此问题 ④:定义数据层接口与映射配置(当然此前要去定义实体类) @Mapper public interface UserDao { @Select("select * from user") public List<User> getAll(); } ⑤:测试类中注入dao接口,测试功能 @SpringBootTest class Springboot08MybatisApplicationTests { @Autowired private BookDao bookDao; @Test public void testGetById() { Book book = bookDao.getById(1); System.out.println(book); } }