当前位置:网站首页>Fundamentals - integrating third-party technology
Fundamentals - integrating third-party technology
2022-07-08 01:01:00 【Printf ('xiaobai ');】
Integrating third party Technology
Integrate Junit
Import the corresponding test starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
Test use @SpringBootTest modification
@SpringBootTest
class Springboot03JunitApplicationTests {
// Inject the object you want to test
@Autowired
private BookDao bookDao;
@Test
public void testBookDao(){
bookDao.save();
}
}
classes Property specifies the boot class
- When your test class is under the package and sub package of your boot class, it can be implemented
- When not under a bag , Will explode, will not find the configuration class , But the annotation of the boot class contains the annotation of the configuration class
@SpringBootTest(classes = Springboot03JunitApplicationTests.class)
perhaps
@SpringBootTest
@ContextConfiguration(classes = Springboot03JunitApplicationTests.class)
Integrate MyBatis
establish SpringBoot Engineering time , Add the corresponding module (MyBatis MySQL)
- MySQL Driver
- MyBatis framework modular
Set data source parameters
- Configure data source information
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
username: root
password: 123456
Define data layer interfaces and mappings ( You can use the configuration file xml form )
- Mapper It is to make the container recognize SQL mapping
@Mapper
public interface BookDao {
@Select("select * from t_book where id = #{id}")
public Book getById(Integer id);
}
test
@SpringBootTest
class Springboot03MyBatisApplicationTests {
@Autowired
private BookDao bookDao;
@Test
public void testGetById(){
Book book = bookDao.getById(1);
System.out.println(book);
}
}
Handling of common problems
- Server time zone setting processing
- mysql8 The time zone must be set for the above
Drive out reminder com.mysql.cj.jdbc.Driver
- mysql8 The time zone must be set for the above
Integrate MyBatis-Plus
add to pom rely on
- The official version is not included mybatis-plus, Alibaba templates can be used to create
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
mapper Interface inheritance BaseMapper
@Mapper
public interface BookDao extends BaseMapper<Book> {
}
matters needing attention
- When there are no coordinates to choose, you need to manually add coordinate dependencies
- There are two ways to solve the problem that there is no table name
- The first is to add @TableName(“ Table name ”)
The second is to prefix the table name in the configuration file
- The first is to add @TableName(“ Table name ”)
mybatis-plus:
global-config:
db-config:
table-prefix: t_
Integrate Druid
Import coordinates
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
To configure yml
- The first one is
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
- The second kind (
recommend)
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
username: root
password: 123456
Ge integrates third-party technology
- Import corresponding starter
- According to the configuration format provided , Configure the configuration items corresponding to non default values
边栏推荐
- Hotel
- Introduction to ML regression analysis of AI zhetianchuan
- 13.模型的保存和載入
- 1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
- 韦东山第三期课程内容概要
- Marubeni official website applet configuration tutorial is coming (with detailed steps)
- Is it safe to open an account on the official website of Huatai Securities?
- 2.非线性回归
- 1.线性回归
- Interface test advanced interface script use - apipost (pre / post execution script)
猜你喜欢

NVIDIA Jetson测试安装yolox过程记录

8.优化器

Letcode43: string multiplication

9.卷积神经网络介绍

Course of causality, taught by Jonas Peters, University of Copenhagen

第一讲:链表中环的入口结点

They gathered at the 2022 ecug con just for "China's technological power"

C # generics and performance comparison

ReentrantLock 公平锁源码 第0篇

Codeforces Round #804 (Div. 2)(A~D)
随机推荐
新库上线 | 中国记者信息数据
22年秋招心得
C# ?,?.,?? .....
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
13.模型的保存和載入
Redis, do you understand the list
5g NR system messages
基础篇——整合第三方技术
13. Model saving and loading
My best game based on wechat applet development
Stock account opening is free of charge. Is it safe to open an account on your mobile phone
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
New library online | information data of Chinese journalists
y59.第三章 Kubernetes从入门到精通 -- 持续集成与部署(三二)
ReentrantLock 公平锁源码 第0篇
QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
Marubeni official website applet configuration tutorial is coming (with detailed steps)
炒股开户怎么最方便,手机上开户安全吗
ReentrantLock 公平锁源码 第0篇