Idea创建SpringBoot项目配置MybatisPlus框架
了解mybatis与mybatisplus 框架
了解mybatis:
官网地址
mybatisplus
官网地址
两个框架区别
mybatisplus图解
实践操作
pom依赖
<!-- mybtaisplus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
entity层:
@Data
@TableName("user")
public class TestEntity {
@TableId(value = "id",type = IdType.INPUT)
private Long id;
@TableField("name")
private String name;
@TableField("age")
private Integer age;
@TableField("email")
private String email;
}
mapper层:
public interface TestMapper extends BaseMapper<TestEntity> {
}
项目启动类
application.yml 文件:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
#过滤springBoot相关日志
main:
banner-mode: off
#开启mybatisplus输出到控制台日志
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
banner: false
测试启动类:
@SpringBootTest
class PlusdemoApplicationTests {
@Autowired
private TestMapper testMapper;
/**
* @Author:RenYaBing
* @Description:通过id查询单条数据
* @CreateTime: 2023/3/2 14:31
* @param: []
* @return: void
**/
@Test
void findSingleInfo() {
TestEntity testEntity= testMapper.selectById(1);
System.out.println(testEntity);
}
}