Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

7.3. MongoRepository

7.3.1. findAll()

			
	@RequestMapping(value = "read", method = RequestMethod.GET, produces = { "application/xml", "application/json" })
	@ResponseStatus(HttpStatus.OK)
	public List<Withdraw> read() {
		return repository.findAll();
	}
			
			

7.3.2. deleteAll()

			
repository.deleteAll();
			
			

7.3.3. save()

			
repository.save(new City("Shenzhen", "China"));
			
			

7.3.4. count()

			
	@RequestMapping("count")
	public long count() {
		return repository.count();
	}
			
			

7.3.5. PageRequest

			
	@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