zoukankan      html  css  js  c++  java
  • MyBatisPlus入门

    一,创建SpringBoot项目

    二,引入依赖

    <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.5</version>
     </dependency>

    三,application.yml配置

    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8
        username: root
        password: root
        driver-class-name: com.mysql.cj.jdbc.Driver
    
    #控制台日志
    mybatis-plus:
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

    四,在 Spring Boot 启动类中添加 @MapperScan 注解,扫描 Mapper 文件夹:

    @MapperScan("com.zl.mapper")

    五,编码

    1,编写实体类TUser

    package com.zl.pojo;
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class TUser {
        private Long id;
        private String username;
        private Integer age;
        private String password;
    }

    2,编写Mapper类 TUserMapper.java

    package com.zl.mapper;
    
    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import com.zl.pojo.TUser;
    
    import java.util.List;
    
    public interface TUserMapper extends BaseMapper<TUser> {
    
        
    }

    3,开始使用

    package com.zl;
    
    import com.zl.mapper.TUserMapper;
    import com.zl.pojo.TUser;
    import org.junit.jupiter.api.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    
    import java.util.List;
    
    @SpringBootTest
    class MybatisPlusApplicationTests {
    
        @Autowired
        private TUserMapper tUserMapper;
    
        @Test
        void contextLoads() {
            List<TUser> userList = tUserMapper.selectList(null);
    
            userList.forEach(System.out::println);
    
        }
    
    }
  • 相关阅读:
    bzoj [POI2015]Myjnie
    bzoj2217 [Poi2011]Lollipop
    Codeforces A Mist of Florescence
    bzoj4380 [POI2015]Myjnie
    bzoj4292 [PA2015]Równanie
    bzoj 3517翻硬币
    模块补充
    python解释器
    __file__、__name__、__dict__方法整理
    软件开发规范
  • 原文地址:https://www.cnblogs.com/zhulei2/p/13258957.html
Copyright © 2011-2022 走看看