Skip to content

DarMi7/mongo-lambda-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongo-lambda-query

a lambda-based object-oriented mongo query plug-in
基于lambda表达式,且面向对象的mongo数据库查询插件。
先赞后看,🌟🌟🌟
Like before you read,🌟🌟🌟

使用步骤:

  1. 引入maven依赖文件
    Importing maven dependency files.
        <dependency>
            <groupId>io.github.darmi7</groupId>
            <artifactId>mongo-lambda-query</artifactId>
            <version>1.3.0</version>
        </dependency>
    
  2. 开启插件注解,加上需要扫描mongo实体的包路径
    Open plug-in annotations, plus the package path that requires scanning mongo entities.
    @EnableMongoLambdaQuery
    @EnableMongoRepositories(basePackages = "com.darmi.demo.repository.mongo")
    public class Application
    
  3. 编写查询代码
    Write query code
        @Repository
        public interface TaskRepository extends MongoRepository<Task, String> {
    
            default Task one(TaskCriteria taskCriteria) {
                return MongoLambdaQuery.lambdaQuery(Task.class)
                    .is(Task::getName, taskCriteria.getName())
                    .one();
            }
            
            default List<Task> list(TaskCriteria taskCriteria) {
                return MongoLambdaQuery.lambdaQuery(Task.class)
                    .gt(Task::getCreated, taskCriteria.getBegin())
                    .lt(Task::getCreated, taskCriteria.getEnd())
                    .list();
            }
            
            
            default Page<Task> search(TaskCriteria taskCriteria) {
                return MongoLambdaQuery.lambdaQuery(Task.class)
                        .is(Task::getName, taskCriteria.getName())
                        .is(Task::getType, taskCriteria.getFuzzyName())
                        .reg(Task::getName, taskCriteria.getName())
                        .gt(Task::getPoints, taskCriteria.getPoints())
                        .gt(Task::getCreated, taskCriteria.getBegin())
                        .lt(Task::getCreated, taskCriteria.getEnd())
                        .page(taskCriteria.getPagination());
            }
        }
    
  4. 具体使用案例参考demo模块,如有什么问题欢迎留言。
    For details, refer to the demo module. If you have any questions, please leave a message.
    原理分析可以查看博客:https://blog.csdn.net/qq_28175019/article/details/129100748

About

mongo lambda query for spring boot plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages