当前位置:网站首页>基础篇——整合第三方技术
基础篇——整合第三方技术
2022-07-07 23:12:00 【printf('小白');】
整合第三方技术
整合Junit
导入对应得测试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>
测试使用@SpringBootTest修饰
@SpringBootTest
class Springboot03JunitApplicationTests {
// 注入你要测试的对象
@Autowired
private BookDao bookDao;
@Test
public void testBookDao(){
bookDao.save();
}
}
classes属性指定引导类
- 当你得测试类在你的引导类得包以及子包下面就可以实现
- 不在一个包下面时,会爆会找找不到配置类,但是引导类得注解上包含了配置类注解
@SpringBootTest(classes = Springboot03JunitApplicationTests.class)
或者
@SpringBootTest
@ContextConfiguration(classes = Springboot03JunitApplicationTests.class)
整合MyBatis
创建SpringBoot工程时,添加对应得模块(MyBatis MySQL)
- MySQL Driver
- MyBatis framework模块
设定数据源参数
- 配置数据源信息
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
username: root
password: 123456
定义数据层接口与映射(可以使用配置文件xml形式)
- Mapper是为了让容器识别到SQL映射
@Mapper
public interface BookDao {
@Select("select * from t_book where id = #{id}")
public Book getById(Integer id);
}
测试
@SpringBootTest
class Springboot03MyBatisApplicationTests {
@Autowired
private BookDao bookDao;
@Test
public void testGetById(){
Book book = bookDao.getById(1);
System.out.println(book);
}
}
常见问题处理
- 服务器时区设定处理
- mysql8以上的必须设定时区
驱动过时提醒 com.mysql.cj.jdbc.Driver
- mysql8以上的必须设定时区
整合MyBatis-Plus
添加pom依赖
- 官方版没有收录mybatis-plus,可以通过阿里模板创建
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
mapper接口继承BaseMapper
@Mapper
public interface BookDao extends BaseMapper<Book> {
}
注意事项
- 没有坐标可以选择的时候需要手动添加坐标依赖
- 爆出不存在表名的两种解决方法
- 第一种在实体类上加上@TableName(“表名”)
第二种在配置文件加上表名前缀
- 第一种在实体类上加上@TableName(“表名”)
mybatis-plus:
global-config:
db-config:
table-prefix: t_
整合Druid
导入坐标
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
配置yml
- 第一种
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
- 第二种(
推荐
)
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
username: root
password: 123456
通用整合第三方技术
- 导入对应的starter
- 根据提供的配置格式,配置非默认值对应的配置项
边栏推荐
- Course of causality, taught by Jonas Peters, University of Copenhagen
- New library online | information data of Chinese journalists
- 1293_FreeRTOS中xTaskResumeAll()接口的实现分析
- Basic mode of service mesh
- ABAP ALV LVC template
- 《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
- AI遮天传 ML-初识决策树
- Basic types of 100 questions for basic grammar of Niuke
- 22年秋招心得
- FOFA-攻防挑战记录
猜你喜欢
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
AI遮天传 ML-初识决策树
Codeforces Round #804 (Div. 2)(A~D)
Redis, do you understand the list
基于卷积神经网络的恶意软件检测方法
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
8道经典C语言指针笔试题解析
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
My best game based on wechat applet development
随机推荐
11.递归神经网络RNN
Deep dive kotlin collaboration (the end of 23): sharedflow and stateflow
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
13. Enregistrement et chargement des modèles
Jemter distributed
An error is reported during the process of setting up ADG. Rman-03009 ora-03113
Play sonar
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
什么是负载均衡?DNS如何实现负载均衡?
华为交换机S5735S-L24T4S-QA2无法telnet远程访问
Invalid V-for traversal element style
Kubernetes static pod (static POD)
新库上线 | CnOpenData中国星级酒店数据
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
手写一个模拟的ReentrantLock
5g NR system messages
炒股开户怎么最方便,手机上开户安全吗
Stock account opening is free of charge. Is it safe to open an account on your mobile phone
Leetcode brush questions