1.什么是MybatisX?

MybatisX 是一款基于 IDEA 的疾速开发插件,不便在应用mybatis以及mybatis-plus开始时简化繁琐的反复操作,进步开发速率。

2.应用MybatisX的益处

  • 节俭大量长久层代码开发工夫
  • 弱小的性能为业务编写提供各类反对
  • 配置简略,辞别各类简单的配置文件

3.如何应用MybatisX?

1.创立一个简略的数据库

2.创立一个简略的Springboot工程

3.在pom.xml文件中引入mybatis-plus依赖

<!--mybatisPlus--><dependency>    <groupId>com.baomidou</groupId>    <artifactId>mybatis-plus-boot-starter</artifactId>    <version>3.5.1</version></dependency>

举荐一个开源收费的 Spring Boot 最全教程:

https://github.com/javastacks/spring-boot-best-practice

4.在File->Settings->Plugins下载MybatiX插件

5.两下SHIFT键搜寻database进入数据库

6.新建Mysql连贯

输出用户、明码及数据库名

Test Connection时会提醒这么一段话:这是时区未设置问题

依据提醒来到Advanced,找到severTimezone,将其设置为GMT(Greenwich Mean Time格林尼治规范工夫)

此时再测试连贯会发现曾经胜利

这时候咱们就能够看见咱们想要连贯的数据库和其对应的表等信息了

右键对应的表,咱们能够看到MybatiX-Generator

点击后咱们会看到这样一个页面,咱们能够在这个页面中设置须要打消的前后缀、文件寄存目录等...

点击Next,在上面是一些配置,咱们勾选Mybatis-Plus的最新版本Mybatix-Plus 3 和 简化开发的Lombok

点击Finish,咱们能够看到MybatisX为咱们主动生成了该表对应的实体类、Mapper文件、Service和绝对应的接口

在yaml中对数据库进行配置:

application.yaml

spring:  datasource:    driver-class-name: com.mysql.cj.jdbc.Driver    url: jdbc:mysql://localhost:3306/user?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT    username: root    password: password

管制层编写办法,应用到Mybatis-Plus中的条件结构器:

package com.example.mybatixtest.controller;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;import com.example.mybatixtest.pojo.User;import com.example.mybatixtest.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class TestController {    @Autowired    UserService userService;    @GetMapping("/test")    public User test(){        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();        userQueryWrapper.eq("user_id",1);        User user = userService.getOne(userQueryWrapper);        return user;    }}

拜访胜利

至此,MybatiX整合springboot的简略配置完结!!

版权申明:本文为CSDN博主「啊陈晓」的原创文章,遵循CC 4.0 BY-SA版权协定,转载请附上原文出处链接及本申明。原文链接:https://blog.csdn.net/weixin_47025166/article/details/125362323

近期热文举荐:

1.1,000+ 道 Java面试题及答案整顿(2022最新版)

2.劲爆!Java 协程要来了。。。

3.Spring Boot 2.x 教程,太全了!

4.别再写满屏的爆爆爆炸类了,试试装璜器模式,这才是优雅的形式!!

5.《Java开发手册(嵩山版)》最新公布,速速下载!

感觉不错,别忘了顺手点赞+转发哦!