SpringBoot整合第三方技術(shù)的實現(xiàn)
整合Junit
在Boot環(huán)境下如何進行單元測設(shè)
- 注解:@SpringBootTest
- 類型:測試類注解
- 位置:測試類上方
- 作用:設(shè)置JUnit加載的SpringBoot啟動類
例:
@SpringBootTest(classes = Springboot07JunitApplication.class) class Springboot07TestApplicationTests {}
相關(guān)屬性
classes:設(shè)置SpringBoot啟動類
注:如果測試類在SpringBoot啟動類的包或者子包中,可以省略啟動類設(shè)置,也就是省略classes的設(shè)定。
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 Springboot07TestApplicationTests { ? ? @Autowired ? ? private BookService bookService; ? ? @Test ? ? public void testService() { ? ? bookService.save(); ? ? } }
SpringBoot整合MyBatis
serverTimezone=UTC一定記得設(shè)置時區(qū),否則idea會爆連接數(shù)據(jù)庫錯誤,讓人以為是密碼錯了?。。?/p>
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 interface BookDao { @Select("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); ? ?} }
到此這篇關(guān)于SpringBoot整合第三方技術(shù)的實現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot整合第三方內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java根據(jù)坐標經(jīng)緯度計算兩點距離5種方法及校驗經(jīng)緯度是否在圓/多邊形區(qū)域內(nèi)的算法推薦
在項目開發(fā)過程中需要根據(jù)兩地經(jīng)緯度坐標計算兩地間距離,下面這篇文章主要給大家介紹了關(guān)于Java根據(jù)坐標經(jīng)緯度計算兩點距離5種方法以及校驗經(jīng)緯度是否在圓/多邊形區(qū)域內(nèi)的算法推薦,需要的朋友可以參考下2023-12-12帶你了解Java數(shù)據(jù)結(jié)構(gòu)和算法之哈希表
這篇文章主要為大家介紹了Java數(shù)據(jù)結(jié)構(gòu)和算法之哈希表,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-01-01SpringBoot+WebSocket+Netty實現(xiàn)消息推送的示例代碼
這篇文章主要介紹了SpringBoot+WebSocket+Netty實現(xiàn)消息推送的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧2020-04-04SpringMVC JSON數(shù)據(jù)交互實現(xiàn)過程解析
這篇文章主要介紹了SpringMVC JSON數(shù)據(jù)交互實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友可以參考下2020-10-10