当前位置:网站首页>基础篇——整合第三方技术
基础篇——整合第三方技术
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
- 根据提供的配置格式,配置非默认值对应的配置项
边栏推荐
- 新库上线 | 中国记者信息数据
- 13.模型的保存和载入
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- 取消select的默认样式的向下箭头和设置select默认字样
- Course of causality, taught by Jonas Peters, University of Copenhagen
- 【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
- 基于卷积神经网络的恶意软件检测方法
- 22年秋招心得
- Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
- Cve-2022-28346: Django SQL injection vulnerability
猜你喜欢
Reptile practice (VIII): reptile expression pack
4.交叉熵
DNS series (I): why does the updated DNS record not take effect?
Deep dive kotlin synergy (XXII): flow treatment
12.RNN应用于手写数字识别
图像数据预处理
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
Jemter distributed
2022-07-07: the original array is a monotonic array with numbers greater than 0 and less than or equal to K. there may be equal numbers in it, and the overall trend is increasing. However, the number
【笔记】常见组合滤波电路
随机推荐
New library launched | cnopendata China Time-honored enterprise directory
Hotel
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
大二级分类产品页权重低,不收录怎么办?
新库上线 | CnOpenData中国星级酒店数据
fabulous! How does idea open multiple projects in a single window?
NVIDIA Jetson test installation yolox process record
接口测试要测试什么?
13.模型的保存和載入
手写一个模拟的ReentrantLock
Deep dive kotlin synergy (XXII): flow treatment
Cancel the down arrow of the default style of select and set the default word of select
ABAP ALV LVC模板
AI遮天传 ML-初识决策树
13. Model saving and loading
Basic mode of service mesh
Reentrantlock fair lock source code Chapter 0
SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
Jouer sonar