com.chevrier.legiondao.boot.BootCommandLine.java Source code

Java tutorial

Introduction

Here is the source code for com.chevrier.legiondao.boot.BootCommandLine.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.chevrier.legiondao.boot;

import com.chevrier.legiondao.config.ConfigJpa;
import com.chevrier.legiondao.entities.Lieu;
import com.chevrier.legiondao.repository.LieuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class BootCommandLine implements CommandLineRunner {

    @Autowired
    LieuRepository repository;

    /*public static void main(String[] args) {
    SpringApplication.run(ConfigJpa.class);
    }*/

    @Override
    public void run(String... strings) throws Exception {
        // save a couple of customers
        repository.save(new Lieu(1, 1));
        repository.save(new Lieu(1, 2));
        repository.save(new Lieu(1, 3));
        repository.save(new Lieu(2, 1));
        repository.save(new Lieu(2, 2));
        // fetch all customers
        System.out.println("Lieu found with findAll():");
        System.out.println("-------------------------------");
        for (Lieu lieu : repository.findAll()) {
            System.out.println(lieu);
        }
        System.out.println();
        // fetch an individual customer by ID
        Lieu lieu1 = repository.findOne(1);
        System.out.println("Customer found with findOne(1L):");
        System.out.println("--------------------------------");
        System.out.println(lieu1);
        System.out.println();
        // fetch customers by last name
        /*System.out.println("Customer found with findByLastName('Bauer'):");
        System.out.println("--------------------------------------------");
        for (Lieu bauer : repository.findByLastName("Bauer")) {
        System.out.println(bauer);
        }*/
    }
}