https://github.com/leosimoes/java-spring-vaadin-customer
Project of a customer CRUD in Java language with Spring Framework and Vaadin.
https://github.com/leosimoes/java-spring-vaadin-customer
java spring vaadin
Last synced: about 2 months ago
JSON representation
Project of a customer CRUD in Java language with Spring Framework and Vaadin.
- Host: GitHub
- URL: https://github.com/leosimoes/java-spring-vaadin-customer
- Owner: leosimoes
- Created: 2024-04-29T16:21:41.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-06T00:34:40.000Z (about 2 years ago)
- Last Synced: 2025-01-30T01:16:37.335Z (over 1 year ago)
- Topics: java, spring, vaadin
- Language: Java
- Homepage:
- Size: 795 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring and Vaadin - Customer
Author: Leonardo Simões
## Development steps
The project development steps were:
1. Create project (in IntelliJ) with:
- Java language (17);
- Spring Framework (6.2.3);
- Dependencies: Vaadin, JPA, H2, DevTools, Lombok.

2. Configure the H2 database:
- In `build.gradle` configure according to the desired type of use:
* `implementation 'com.h2database:h2'`;
* `runtimeOnly 'com.h2database:h2'`;
* `testImplementation 'com.h2database:h2'`;
- In `application.properties`:
```properties
# ================================================================
# APPLICATION
# ================================================================
spring.application.name=Java-Spring-Vaadin-Customer
# ================================================================
# DATASOURCE - H2 DATABASE
# ================================================================
spring.datasource.url=jdbc:h2:mem:proddb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=leo
spring.datasource.password=senha
spring.h2.console.enabled=true
spring.h2.console.path=/h2
```

- test access to the H2 console at `http://localhost:8080/h2/`:

Note:
- By default, the usename would be "sa" and the password "", and the h2 console would be disabled.
4. Create `CustomerEntity` class:
- in the `entities` package;
- with attributes UUID id, String firstName, String lastName;
- corresponding to the table named `CUSTOMERS`.

5. Create `CustomerRepository` interface:
- in the `repositories` package;
- annotated with `@Repository`;
- extends `JPARepository`;
- with methods:
* `Optional findById(UUID id);`
* `Optional findById(UUID id);`
* `List findByFirstName(String firstName);`
* `List findByLastName(String lastName);`
* `List findByFirstNameAndLastName(String firstName, String lastName);`

6. Create `MainView` class:
- in the `views` package;
- annotated with `@Route("customers")`;
- extends `VerticalLayout`;
- with a constructor annotated with `@Autowired` with a parameter (repository) and customize the screen inside it.


## References
Spring - Guides - Criando UI CRUD com Vaadin:
https://spring.io/guides/gs/crud-with-vaadin