SpringBoot整合Druid

  1. 导入Druid对应的starter

	com.alibaba
	druid-spring-boot-starter
	1.2.6


	com.baomidou
	mybatis-spring-boot-starter
	3.4.3

  1. 变更Druid的配置方式
spring:
  datasource:
  	druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC	
      username: root
      password: root
  1. 定义数据层接口与映射配置
@Mapper
public interface UserDao {
	@Select("select * from user")
	public List<User> getAll();
}
  1. 测试类中注入dao接口,测试功能
@SpringBootTest
class Springboot07MybatisApplicationTests {
	@Autowired
	private BookDao bookDao;
	@Test
	public void testGetById() {
		Book book = bookDao.getById(1);
		System.out.println(book);
}
}

你可能感兴趣的:(SpringBoot,spring,boot,mybatis)