SpringBoot整合MP(MybatisPlus)最简单的案例

MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

官网给了一个简单的Demo,是H2数据库的,我这里改写成mysql的,并且简化了步骤。

步骤:

1、创建一个空的maven项目,添加spring-boot和mysql等5个依赖,

    <dependencies>
<!--        springboot基本必须-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
<!--        springboot-test 测试需要-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
<!--        MP 主角 mybatis plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>
<!--        lombok 简化getter,setter-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
<!--        mysql 数据库-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

2、添加application.yaml,添加数据库配置。

3、创建启动类和mapper.和唯一的对象User。

 

 

 4、项目跑起来。

5、准备数据库。创建一个user表,不然报错,连不上数据库。

 

6、添加一个测试文件。

 

 官方文档的范例修改为mysql了。

到这里本案完成。但你以为结束了吗?卷起来吧!https://github.com/baomidou/mybatis-plus-samples

 

  • mybatis-plus-sample-quickstart: 快速开始示例
  • mybatis-plus-sample-quickstart-springmvc: 快速开始示例(Spring MVC版本)
  • mybatis-plus-sample-reduce-springmvc: 简化掉默认mapper类示例(Spring MVC版本)
  • mybatis-plus-sample-generator: 代码生成器示例
  • mybatis-plus-sample-crud: 完整 CRUD 示例
  • mybatis-plus-sample-wrapper: 条件构造器示例
  • mybatis-plus-sample-pagination: 分页功能示例
  • mybatis-plus-sample-active-record: ActiveRecord示例
  • mybatis-plus-sample-sequence: Sequence示例
  • mybatis-plus-sample-execution-analysis: Sql执行分析示例
  • mybatis-plus-sample-performance-analysis: 性能分析示例
  • mybatis-plus-sample-optimistic-locker: 乐观锁示例
  • mybatis-plus-sample-sql-injector: 自定义全局操作示例
  • mybatis-plus-sample-auto-fill-metainfo: 公共字段填充示例
  • mybatis-plus-sample-logic-delete: 逻辑删除示例
  • mybatis-plus-sample-multi-datasource: 多数据源示例
  • mybatis-plus-sample-enum: 枚举注入示例
  • mybatis-plus-sample-dynamic-tablename: 动态表名示例
  • mybatis-plus-sample-tenant: 多租户示例
  • mybatis-plus-sample-typehandler: 类型处理器示例,例如 json 字段对象转换
  • mybatis-plus-sample-deluxe: 完整示例(包含 分页、逻辑删除、自定义全局操作 等绝大部分常用功能的使用示例,相当于大整合的完整示例)
  • mybatis-plus-sample-assembly: 分离打包示例
  • mybatis-plus-sample-resultmap: 使用 resultMap 示例
  • mybatis-plus-sample-id-generator: 自定义ID生成示例
  • mybatis-plus-sample-id-string: 字符串ID生成示例
  • mybatis-plus-sample-no-spring: 不使用spring下的示例
  • mybatis-plus-sample-pagehelper: 使用pagehelper进行分页
  • mybatis-plus-sample-association: 联表查询示例

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东宇科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值