Skip to content

Instantly share code, notes, and snippets.

Last active Jan 19, 2018
What would you like to do?

Référence :

  • initialiser un projet avec

    • maven
    • java
    • 2.0.0.M7
  • ajouter un service HelloService (component -> service, repository, controller) qui retourne un Greeting.

public class HelloService {
    public String hello(String name) {...}
  • Écrire le test
public class HelloServiceTest {

    private HelloService helloService;
    public void simple() {
  • Exécuter Run focus test method

  • Implementer CommandLineRunner

    • injecter le service
public class App implements CommandLineRunner{
    private HelloService helloService;
    public void run(String... args) throws Exception {
public class HelloController {
    private HelloService helloService;
    public Greeting hello(@RequestParam String param) {
        return helloService.hello(param);
  • spring-data
    • ajouter la dépendance spring-boot-starter-data-jpa
    • ajouter le repository de Greeting
  public interface GreetingRepository extends CrudRepository<Greeting, Long>{

    List<Greeting> findByName(String name);
  • ajouter l'Id dans Greeting
  • ajouter la méthode HelloService.all()
  • ajouter dans RestController
    public List<Greeting> all(@PathVariable String name) {
        return helloService.all(name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment