开发者

SpringBoot整合第三方技术的实现

目录
  • 整合Junit
  • SpringBoot整合MyBajstis

整合Junit

在Boot环境下如何进行单元测设

  • 注解:@SpringBootTest
  • 类型:测试类注解
  • 位置:测试类上方
  • 作用:设置JUnit加载的SpringBoot启动类

例:

@SpringBootTest(classes = Springboot07Junit开发者_JS开发Application.class)
class Springboot07TestApplicationTests {}

相关属性

classes:设置SpringBoot启动类

注:如果测试类在SpringBoot启动类的包或者子包中,可以省略启动类设置,也就是省略classes的设定。

import com.ityc.service.BookService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class Springboot07Tewww.devze.comstApplicationTests {

  @Autowired
  private BookService bookService;

  @Test
  public void testService() {
  bookService.sajavascriptve();
  }

}

SpringBoot整合MyBATis

serverTimezone=UTC一定记得设置时区,否则idea会爆连接数据库错误,让人以为是密码错了!!!

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC
    username: root
    password: lyc
    type: com.alibaba.druid.pool.DruidDataSource
@Mapper
public interfacewww.devze.com BookDao {
    @Sejavascriptlect("select * from tbl_book where id = #{id}")
    public Book getById(Integer id);
}

测试

@SpringBootTest
class Springboot08MybatisApplicationTests {

 @Autowired
 private BookDao bookDao;

 @Test
 void testGetById() {
   Book book = bookDao.getById(10);
   System.out.println(book);
 }

}

到此这篇关于SpringBoot整合第三方技术的实现的文章就介绍到这了,更多相关SpringBoot整合第三方内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜