ms.date | author | ms.author | ms.reviewer |
---|---|---|---|
02/22/2023 | KarlErickson | karler | seal |
Create a new
Todo
Java class. This class is a domain model mapped onto thetodo
table that will be created automatically by JPA. The following code ignores thegetters
andsetters
methods.packagecom.example.demo; importjavax.persistence.Entity; importjavax.persistence.GeneratedValue; importjavax.persistence.Id; @EntitypublicclassTodo { publicTodo() { } publicTodo(Stringdescription, Stringdetails, booleandone) { this.description = description; this.details = details; this.done = done; } @Id@GeneratedValueprivateLongid; privateStringdescription; privateStringdetails; privatebooleandone; }
Edit the startup class file to show the following content.
importorg.springframework.boot.SpringApplication; importorg.springframework.boot.autoconfigure.SpringBootApplication; importorg.springframework.boot.context.event.ApplicationReadyEvent; importorg.springframework.context.ApplicationListener; importorg.springframework.context.annotation.Bean; importorg.springframework.data.jpa.repository.JpaRepository; importjava.util.stream.Collectors; importjava.util.stream.Stream; @SpringBootApplicationpublicclassDemoApplication { publicstaticvoidmain(String[] args) { SpringApplication.run(DemoApplication.class, args); } @BeanApplicationListener<ApplicationReadyEvent> basicsApplicationListener(TodoRepositoryrepository) { returnevent->repository .saveAll(Stream.of("A", "B", "C").map(name->newTodo("configuration", "congratulations, you have set up correctly!", true)).collect(Collectors.toList())) .forEach(System.out::println); } } interfaceTodoRepositoryextendsJpaRepository<Todo, Long> { }
[!INCLUDE spring-default-azure-credential-overview.md]
Start the application. You'll see logs similar to the following example:
2023-02-01 10:29:19.763 DEBUG 4392 --- [main] org.hibernate.SQL : insert into todo (description, details, done, id) values (?, ?, ?, ?) com.example.demo.Todo@1f