使用,mybatis-plus快速自动生成代码

前言

为了使自动生成代码更加简洁。baomidou 推出了 MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生


一、什么是mybatis-plus

升级版的mybatis,目的是让mybatis更易于使用, 用官方的话说“为简化而生”

二、使用步骤

1.创建springboot工程,加入必要的依赖

代码如下:


    org.springframework.boot
    spring-boot-starter-parent
    2.6.7
     

依赖


    1.8


    
        org.springframework.boot
        spring-boot-starter-data-jdbc
    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
        mysql
        mysql-connector-java
        runtime
    
    
        org.projectlombok
        lombok
        true
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    
    
    
        com.baomidou
        mybatis-plus-boot-starter
        3.4.3.4
    
    
    
        com.baomidou
        mybatis-plus-generator
        3.4.0
    
    
        org.springframework.boot
        spring-boot-starter-freemarker
    

2 .编写项目配置文件,项目名称,数据库配置

server:
    port: 8080
spring:
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/T271?servertimezone=Asia?Shanghai&useUnicode=true&charaterEncoding=utf-8
        username: root
        password: 123
mybatis-plus:
    mapper-locations: classpath*:/mapper/*Mapper.xml
    type-aliases-package: com.zking.mybatispluspro.model
    configuration:
        #驼峰命名规则
        map-underscore-to-camel-case: true
logging:
    level:
        com.zking.mybatispluspro.mapper: debug

3.启动类,指定mapper接口的位置

使用,mybatis-plus快速自动生成代码_第1张图片

4.导入代码生成器见官网https://baomidou.com/pages/d357af/

使用,mybatis-plus快速自动生成代码_第2张图片

5.运行代码生成器

 

使用,mybatis-plus快速自动生成代码_第3张图片


 

 

你可能感兴趣的:(开发小工具,开发语言,java,idea)