After creating the basic project, let’s add some entities.
One of the cool things about JHipster is JDL (Jhipster Domain Language).
Its a DSL for creating projects and entities.
Create a file named "hip.jdl" and put in the following:
entity Person {
name String required
age Integer min(0) max(142)
}
(Feel free to mess around with your JDL and make it more complicated, but for this example, let’s keep it simple)
Import the JDL by running jhipster import-jdl hip.jdl
Now open the project with your favorite IDE (like IntelliJ IDEA for example) and take
a look at the PersonController.
JHipster automatically creates an AuditEvent database for auditing (create, update, delete record events).
Open up the file named "AuditResource" under the "com.mycompany.myapp.web.rest" package (Under src/main/java/).
It should have a "getAll" method that looks something like this:
@GetMapping
public Mono<ResponseEntity<Flux<AuditEvent>>> getAll(ServerHttpRequest request, Pageable pageable) {
return auditEventService.count()
.map(total -> new PageImpl<>(new ArrayList<>(), pageable, total))
.map(page -> PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromHttpRequest(request), page))
.map(headers -> ResponseEntity.ok().headers(headers).body(auditEventService.findAll(pageable)));
}
WebFlux allows you to return Reactor types like Mono and Flux from controller methods
and implements a reactive, asynchronous web server using Netty by default.
A typical web server uses a large number of Threads and handles each request in one thread.
The problem with this is Threads in Java are kind of heavyweight
(this should be fixed by project
Loom and virtual threads in Java 15+).
This allows a single Thread to block without holding back the entire application;
however, the number of concurrent requests you can handle is limited by the number of threads
your server can support.
Netty instead uses an EventLoop
per Thread for I/O.
WebFlux enables and simplifies the Java API using Reactive Streams (of which Reactor is one implementation).