引入相关依赖

<!-- 提示:
     1. common-mybatis-plus:2100.8.9 中只有4个类文件,是对硬删除、硬查询的扩展支持,如果你不想引入依赖的话,你可以把这四个文件复制到自己的项目中即可
     2. common-mybatis-plus:2100.8.9 对应mybatis-plus版本3.5.4.1,扩展功能有:硬删除、硬查询
     3. common-mybatis-plus:2100.8.7 对应mybatis-plus版本3.5.2,扩展功能有:硬删除
-->
<dependency>
    <groupId>com.idea-aedi</groupId>
    <artifactId>common-mybatis-plus</artifactId>
    <version>2100.8.9</version>
    <exclusions>
        <!-- 提示:common-spring是一些其它工具类,不想要的话这里直接exclusion即可 -->
        <exclusion>
            <groupId>com.idea-aedi</groupId>
            <artifactId>common-spring</artifactId>
        </exclusion>
    </exclusions>
</dependency>

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

启用增强功能

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

/**
 * 导出sql注入器
 */
// 或:@ComponentScan(basePackages = "com.ideaaedi.commonmp.injector")
@Import(com.ideaaedi.commonmp.injector.MybatisPlusSqlInjector.class)
@SpringBootApplication
public class StartUp {
    public static void main(String[] args) {
        SpringApplication.run(StartUp.class, args);
    }
}

使用示例

  • 编写mapper
    import com.ideaaedi.commonmp.mapper.BaseMapperExt;
    import com.ideaaedi.demo.entity.UserPO;
    import org.apache.ibatis.annotations.Mapper;
    
    @Mapper
    public interface UserMapper extends BaseMapperExt<UserPO> {
    }
    
  • 编写service
    import com.ideaaedi.commonmp.service.IServiceExt;
    import com.ideaaedi.demo.entity.UserPO;
    
    public interface UserService extends IServiceExt<UserPO> {
    }
    
  • 编写service-impl
    import com.ideaaedi.commonmp.service.ServiceImplExt;
    import com.ideaaedi.demo.entity.UserPO;
    import com.ideaaedi.demo.mapper.UserMapper;
    import com.ideaaedi.demo.service.UserService;
    import org.springframework.stereotype.Service;
    
    @Service
    public class UserServiceImpl extends ServiceImplExt<UserMapper, UserPO> implements UserService {
    }
    
  • 调用硬删除、硬查询方法即可
    扩展mybatis-plus,保留逻辑删、逻辑查的前提下,扩展硬删除、硬查询-LMLPHP

相关资料

12-27 20:39