# mybatis-plus-query **Repository Path**: joker-pper/mybatis-plus-query ## Basic Information - **Project Name**: mybatis-plus-query - **Description**: mybatis-plus查询增强工具包,提供获取属性对应的列名及lambda属性列名等方法。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 1 - **Created**: 2018-10-29 - **Last Updated**: 2025-01-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mybatis-plus-query #### 项目介绍 基于mybatis-plus用于增强mapper查询方法的框架,用于自定义查询方法sql中动态条件的生成(即可使用Wrapper构造条件) #### 使用说明 依赖mybatis-plus 3.0.x版本 Mapper类必须继承BaseMapper 默认需要在Mapper上加入@QuerySupport启用 配置@QuerySupport的方法名称必须唯一(且为xml方法时result类型会被忽略) 在对应的查询方法中使用@QuerySupport,即可完成增强sql 当mapper方法中存在@Param(Constants.WRAPPER) Wrapper wrapper参数时才会根据所配置的sql语句生成对应的动态sql (所提供的sql支持bind、include,过于复杂的可能不支持) 若需要使用Wrapper的select指定列,对应的sql则需要以 SELECT %s FROM 的方式 使用@QuerySupport会默认将实体@TableName所配置的resultMap作为当前方法的resultMap 类型优先级 (若未存在注解,当类型与mapper泛型不一致时使用其本身) @ResultType > @ResultMap > @Table(在类型一致时应用存在的resultMap) mybatis-plus-query-core 为核心实现包(必须引入) mybatis-plus-query-boot-starter 为boot配置包(可选) ### 示例项目 mybatis-plus-query-test (使用core及boot-starter配置) ### 如何引入 1. master jar文件夹为打包好的各版本jar文件 2. 使用 jitpack.io (依赖于发行版) ``` jitpack.io https://jitpack.io com.gitee.joker-pper mybatis-plus-query x.x.x com.gitee.joker-pper.mybatis-plus-query mybatis-plus-query-core x.x.x com.gitee.joker-pper.mybatis-plus-query mybatis-plus-query-boot-starter x.x.x ``` #### maven引入本地jar及springboot如何正确打包 可参考--> [cascade项目](https://gitee.com/joker-pper/mybatis-plus-cascade.git) #### spring mvc如何使用mybatis-plus-query (核心为在spring容器启动后刷新mybatis已生成的方法) 参考cascade项目的MybatisPlusConfig配置,除了@ConfigurationProperties注解不存在外,然后使用下面配置即可 的方式进行加载配置 ``` @Component public class QuerySupportInitListener implements ApplicationListener { @Resource private QuerySupportMethod querySupportMethod; @Override public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { if (contextRefreshedEvent.getApplicationContext().getParent() == null) { querySupportMethod.injectQuerySupportMappedStatement(); } } } ``` ### 版本介绍 1.0 支持mp3.0.1-3.0.5 1.1 支持mp3.0.1-3.1.1 修改为在原有mappedStatement上覆盖sqlSource及resultMaps 1.1.1 支持mp3.0.1-3.1.1 验证必须找到mappedStatement 支持Results注解的使用 (@ResultType > @ResultMap > @Results > @Table) 1.1.2 支持mp3.0.1-3.1.1 提供获取列名的方法 2.0 支持mp3.1.2 支持获取列名的方法 2.0.1 添加lambda属性工具类,可直接获取所对应实体类的属性/列名 (mp3.1.1以下版本若需要可参考[LambdaPropertyUtils](https://gitee.com/joker-pper/mybatis-plus-query/blob/2.0/mybatis-plus-query-core/src/main/java/com/devloper/joker/mybatis/plus/query/core/LambdaPropertyUtils.java) 实现,SFunction可能要替换为Property. 也可以直接使用通过lambda表达式获取实体类的属性名称的工具包[戳这里](https://github.com/joker-pper/lambda-property))