中国广东省深圳市望海路半岛城邦三期 518067 +86 13113668890 <netkiller@msn.com>
$Id: book.xml 606 2013-05-29 09:52:58Z netkiller $
版权 © 2015-2018 Neo Chan
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
http://www.netkiller.cn |
---|
http://netkiller.github.io |
http://netkiller.sourceforge.net |
我的系列文档
编程语言
Netkiller Architect 手札 | Netkiller Developer 手札 | Netkiller Java 手札 | Netkiller Spring 手札 | Netkiller PHP 手札 | Netkiller Python 手札 |
---|---|---|---|---|---|
Netkiller Testing 手札 | Netkiller Cryptography 手札 | Netkiller Perl 手札 | Netkiller Docbook 手札 | Netkiller Project 手札 | Netkiller Database 手札 |
默认不需要设置,除非你的包不在当前包下,或者命令不是 repository。
@EnableMongoRepositories(basePackages = "cn.netkiller.repository")
@RequestMapping(value = "read", method = RequestMethod.GET, produces = { "application/xml", "application/json" })
@ResponseStatus(HttpStatus.OK)
public List<Withdraw> read() {
return repository.findAll();
}
repository.deleteAll();
repository.save(new City("Shenzhen", "China"));
@RequestMapping("count")
public long count() {
return repository.count();
}
boolean isExists = userRepository.exists(user.getId());
memberRepository.existsById(id);
List<User> findByName(String name);
List<User> users = userRepository.findByName("Eric");
List<User> users = userRepository.findAll(new Sort(Sort.Direction.ASC, "name"));
Pageable pageable = PageRequest.of(0, 1);
Page<User> page = userRepository.findAll(pageable);
List<User> users = pages.getContent();
Page<User> findByLastname(String lastname, Pageable pageable);
@RequestMapping(value = "read/{size}/{page}", method = RequestMethod.GET, produces = { "application/xml", "application/json" })
@ResponseStatus(HttpStatus.OK)
public List<Withdraw> readPage(@PathVariable int size, @PathVariable int page){
PageRequest pageRequest = new PageRequest(page-1,size);
return repository.findAll(pageRequest).getContent();
}
URL翻页参数,每次返回10条记录
第一页 http://localhost:8080/v1/withdraw/read/10/1.json
第二页 http://localhost:8080/v1/withdraw/read/10/2.json
...
第五页 http://localhost:8080/v1/withdraw/read/10/5.json
List<User> findByNameStartingWith(String regexp);
List<User> findByNameEndingWith(String regexp);
List<User> users = userRepository.findByNameStartingWith("N");
List<User> users = userRepository.findByNameEndingWith("o");
List<User> findByAgeBetween(int ageGT, int ageLT);
List<User> users = userRepository.findByAgeBetween(20, 50);
public interface PersonRepository extends MongoRepository<Person, String> {
@Query("{ 'name' : ?0 }")
List<Person> findWithQuery(String userId);
}
@Query(value = "{'statusHistories':{$elemMatch:{'status':{$in:['PROCESSABLE']}}},'created' : { '$gt' : { '$date' : ':?0' } , '$lt' : { '$date' : ':?1'}}}", count = true)
Long countMe(@Param("dateFrom") Date datefrom, @Param("dateTo") Date dateTo);
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。