Idea中SpringBoot项目配置MybatisPlus框架

Idea创建SpringBoot项目配置MybatisPlus框架

  • 了解mybatis与mybatisplus 框架
    • 两个框架区别
      • mybatisplus图解
        • 实践操作

了解mybatis与mybatisplus 框架

了解mybatis:
官网地址

mybatisplus
官网地址

两个框架区别

Idea中SpringBoot项目配置MybatisPlus框架_第1张图片

mybatisplus图解

Idea中SpringBoot项目配置MybatisPlus框架_第2张图片

实践操作

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> {

}

项目启动类
Idea中SpringBoot项目配置MybatisPlus框架_第3张图片
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);
    }
}

你可能感兴趣的:(spring,boot,intellij-idea,mybatis)