当前位置:网站首页>基础篇——整合第三方技术
基础篇——整合第三方技术
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
- 根据提供的配置格式,配置非默认值对应的配置项
边栏推荐
- 基于人脸识别实现课堂抬头率检测
- Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
- Interface test advanced interface script use - apipost (pre / post execution script)
- 13. Model saving and loading
- Letcode43: string multiplication
- 赞!idea 如何单窗口打开多个项目?
- 手机上炒股安全么?
- Su embedded training - Day3
- Invalid V-for traversal element style
- 6.Dropout应用
猜你喜欢

SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)

国外众测之密码找回漏洞

Cancel the down arrow of the default style of select and set the default word of select

51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up

New library launched | cnopendata China Time-honored enterprise directory

Binder core API

取消select的默认样式的向下箭头和设置select默认字样

How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?

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

Reptile practice (VIII): reptile expression pack
随机推荐
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
韦东山第二期课程内容概要
11.递归神经网络RNN
Invalid V-for traversal element style
Kubernetes static pod (static POD)
攻防演练中沙盘推演的4个阶段
Analysis of 8 classic C language pointer written test questions
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Four stages of sand table deduction in attack and defense drill
基于卷积神经网络的恶意软件检测方法
14.绘制网络模型结构
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
[note] common combined filter circuit
Jemter distributed
Codeforces Round #804 (Div. 2)(A~D)
5.过拟合,dropout,正则化
Su embedded training - Day3
Cve-2022-28346: Django SQL injection vulnerability
【笔记】常见组合滤波电路
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布