当前位置:网站首页>基础篇——整合第三方技术
基础篇——整合第三方技术
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
- 根据提供的配置格式,配置非默认值对应的配置项
边栏推荐
- 10.CNN应用于手写数字识别
- Summary of the third course of weidongshan
- Su embedded training - Day3
- The method of server defense against DDoS, Hangzhou advanced anti DDoS IP section 103.219.39 x
- Reentrantlock fair lock source code Chapter 0
- 新库上线 | 中国记者信息数据
- [reprint] solve the problem that CONDA installs pytorch too slowly
- STL--String类的常用功能复写
- After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
- 【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
猜你喜欢
新库上线 | CnOpenData中国星级酒店数据
4.交叉熵
13.模型的保存和载入
3 years of experience, can't you get 20K for the interview and test post? Such a hole?
C # generics and performance comparison
Jemter distributed
玩轉Sonar
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
New library online | cnopendata China Star Hotel data
Image data preprocessing
随机推荐
Implementation of adjacency table of SQLite database storage directory structure 2-construction of directory tree
Service mesh introduction, istio overview
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Lecture 1: the entry node of the link in the linked list
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
Langchao Yunxi distributed database tracing (II) -- source code analysis
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
Leetcode brush questions
What is load balancing? How does DNS achieve load balancing?
Codeforces Round #804 (Div. 2)(A~D)
ReentrantLock 公平锁源码 第0篇
13.模型的保存和載入
German prime minister says Ukraine will not receive "NATO style" security guarantee
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
6.Dropout应用
华泰证券官方网站开户安全吗?
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
Image data preprocessing
They gathered at the 2022 ecug con just for "China's technological power"