Coder Social home page Coder Social logo

mybatisplusplus's Introduction

MybatisPlus增强工具

MybatisPlus在配置了全局逻辑删除之后, 所有的RUD接口都会自动添加逻辑删除字段限制

该增强工具用于在已经配置了全局逻辑删除之后实现非逻辑删除操作

该增强工具遵循MybatisPlus的**, 只做增强, 不做改变

在SpringBoot中使用

  1. 添加仓库

    Gradle

    repositories {
        maven { url 'https://www.jitpack.io' }
        ...
    }

    Maven

    <repositories>
    	<repository>
    		<id>jitpack.io</id>
    		<url>https://www.jitpack.io</url>
    	</repository>
    </repositories>
  2. 引入依赖

    最新版为: 3.4.2-release

    Gradle

    dependencies {
        implementation 'com.violetfreesia:mybatisplusplus:latestVersion'
    }

    Maven

    <dependency>
    	<groupId>com.violetfreesia</groupId>
    	<artifactId>mybatisplusplus</artifactId>
    	<version>latestVersion</version>
    </dependency>
  3. 配置注入器

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import com.violetfreesia.mybatisplusplus.IllogicalMethodInjector;
    
    /**
     * @author violetfreesia
     */
    @Configuration
    public class MybatisPlusConfig {
        @Bean
        public AbstractSqlInjector illogicMethodInjector() {
            return new IllogicalMethodInjector();
        }
    }
  4. 将原来继承BaseMapper的接口改为继承自IllogicalBaseMapper

    //原来为 public interface UserMapper extends BaseMapper<User>
    public interface UserMapper extends IllogicalBaseMapper<User> {
    	...
    }
  5. 将原来继承IService的接口改为继承自IllogicalBaseService

    //原来为 public interface UserService extends IService<User>
    public interface UserService extends IllogicalBaseService<User> {
    	...
    }
  6. 将原理继承ServiceImpl的Service实现类改为继承自IllogicalBaseServiceImpl

    //原来为 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService
    public class UserServiceImpl extends IllogicalBaseServiceImpl<UserMapper, User> implements UserService {
    	...
    }
  7. 使用方法

    调用增强工具提供的方法, 只需要在方法名后添加Illogical即可, 使用方法与原MybatPlus提供的方法相同

  8. 使用案例

    /**
     * @author violetfreesia
     */
    @RestController
    public class UserController {
        private final UserService userService;
    
        public UserController(UserService userService) {
            this.userService = userService;
        }
    
        @GetMapping("/user/{userId}")
        public User getById(@PathVariable String userId) {
            // 这里调用的方法就是该增强工具提供的方法
            return userService.getByIdIllogical(userId);
        }
    }

    上面演示的是在全局配置了逻辑删除的情况下, 调用增强工具提供的查询方法, 该方法是可以查询到已经逻辑删除的数据的(未被删除的肯定也是可以的)

  9. 增强工具提供的方法

    该增强工具提供的所有方法名都是在原方法名后添加Illogical

    Sevice CRUD

    参见MybatisPlus官网Remove, Update, Get, List, Page, Count 的所有方法

    Mapper CRUD

    参见MybatisPlus官网Delete, Update, Select 部分的所有方法

mybatisplusplus's People

Contributors

violetfreesia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.