spring data mongo queryByExample
2016-11-02 00:00
441 查看
##maven依赖
##dao
##controller
##config
##使用
##doc
[Query by Example](http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#Query by Example)
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency>
##dao
public interface ArticleDao extends MongoRepository<Article,String>,QueryByExampleExecutor<Article> { }
##controller
@RequestMapping("/list") public Page<Article> list(Article article,@PageableDefault(sort = { "createdAt" },page = 0,size = 10) Pageable pageable){ ExampleMatcher matcher = ExampleMatcher.matching() .withMatcher("content", ExampleMatcher.GenericPropertyMatchers.contains()); Example<Article> example = Example.of(article,matcher); return articleDao.findAll(example,pageable); }
##config
@SpringBootApplication @EnableSpringDataWebSupport public class MongoApplication { public static void main(String[] args) { SpringApplication.run(MongoApplication.class, args); } }
##使用
curl -i http://localhost:8080/article/list?content=软件
##doc
[Query by Example](http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#Query by Example)
相关文章推荐
- spring data mongo groupby实例
- springboot学习笔记(六)spring data mongo以及querydsl在此的应用
- 简化MongoAPI(spring-data-mongo)第三部分----Criteria和Query对象的使用
- logstash 如何处理 mongodb 导出来的 _id value数据。 how to custom fields of logstash by mongo mapreduce exported data.(example format: {_id:"xxx"} , value:{})
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query
- [MongoDB] Spring Data Mongo
- spring-data-mongodb的MongoTemplate 使用小例子
- Referenced file contains errors(http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.x)
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query
- Plugin execution not covered by lifecycle configuration” for Spring Data Maven Builds
- spring data for mongo
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exce
- springmvc+spring data 在用EntityManager类的query.getResultList()类型转换
- Spring Data MongoDB example with Spring MVC 3.2
- Spring Data之@Query中的org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML
- spring-data-mongo中数据插入异常报告
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exc
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query;
- spring-data-mongo :Error creating bean with name 'indexCreationHelper':
- Spring Remoting by HTTP Invoker Example--reference