1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| package org.sid.web;
import java.util.List;
import javax.websocket.server.PathParam;
import org.sid.dao.ContactRepository;
import org.sid.entities.Contact;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController //Il s'agit d'un controller classique de Spring.
// Il permet de faire la conversion JSON -> Objet et inversement automatiquement grace à Spring 4
@CrossOrigin("*") //j'autorise les navigateur à acceder ici via une url TRES IMPORTANT SANS CA CA NE MARCHERA PAS !
public class ContactRestService {
@Autowired // injecter ta dépendance
private ContactRepository contactRepository;
@RequestMapping(value="/chercherContact",method=RequestMethod.GET)
public Page<Contact> chercher(
@RequestParam(name="mc", defaultValue="") String mc/*motclé*/,
@RequestParam(name="page", defaultValue="0") int page,
@RequestParam(name="size", defaultValue="5")int size){
return contactRepository.chercher("%"+mc+"%", new PageRequest(page, size));
}
} |
Partager