Spring Boot Database Admin documentation
1. Introduction
The following documentation outlines how to install, configure and customize Spring Boot Database Admin panel. Refer to this document for troubleshooting and if you still encounter problems, please report it as an issue on Github.
2. Getting started
Getting started with Spring Boot Database Admin requires including it as a dependency and then performing a simple configuration step.
2.1 Installation
At the moment the code is not yet distributed on Maven, so it is necessary to build and install manually. Clone the Github repo and mvn install
the project into your local repository. Then, include the dependency in your pom.xml
:
<dependency>
<groupId>tech.ailef</groupId>
<artifactId>spring-boot-db-admin</artifactId>
<version>0.0.4</version>
</dependency>
TIP The version in this snippet might be different from the one you pulled from Github. Make sure to edit it to match the version contained in the project's pom.xml
file.
2.2 Configuration
After including the dependency, a few configuration steps are required on your end in order to integrate the library into your project.
The first one is configuring your application.properties
file:
# The first-level part of the URL path: http://localhost:8080/${baseUrl}/
dbadmin.baseUrl=admin
# The package that contains your @Entity classes
dbadmin.modelsPackage=your.models.package
# OPTIONAL PARAMETERS
# Whether to enable to web interface
# dbadmin.enabled=true
#
# Set to true if you need to run the tests, as it will customize
# the database configuration for the internal DataSource
# dbadmin.testMode=false
After this, you must tell Spring to import the Spring Boot Database Admin configuration. To do this, annotate your @SpringBootApplication
class containing the main
method with the following:
@ImportAutoConfiguration(DbAdminAutoConfiguration.class)
This will autoconfigure the various Spring Boot Database Admin components when your application starts.
If everything is setup correctly, you will see Spring Boot Database Admin confirming it in the log messages that appear when you start your application. Keep in mind that if you specify the wrong models package, it will still work but provide you an empty interface. To check, visit http://localhost:8080/admin.
3. Customization
There are two ways to customize the appearance and behaviour of Spring Boot Database Admin:
- Applying annotations on your
@Entity
classes, fields and methods - Using the Settings panel through the web interface
Annotations are used primarily to customize behaviour and add custom logic to your classes. If, instead, you're looking to customize appearance of the web UI, it's most likley through the Settings panel.
3.1 Supported annotations
3.1.1 @DisplayName
@DisplayName
public String getFullName() {
return firstName + " " + lastName;
}
When displaying a reference to an item, by default we show its primary key. If a class has a @DisplayName
, this method will be used in addition to the primary key whenever possible, giving the user a more readable option.
3.1.2 @DisplayFormat
@DisplayFormat(format = "$%.2f")
private Double price;
Specify a format string to apply when displaying the field.
3.1.3 @ComputedColumn
@ComputedColumn
public double totalSpent() {
double total = 0;
for (Order o : orders) {
total += o.total();
}
return total;
}
This annotation can be used to add values computed at runtime that are shown like additional columns.
3.1.4 @Filterable
@Filterable
private LocalDate createdAt;
Place on one or more fields in a class to activate the faceted search feature. This will allow you to easily combine all these filters when operating on the table. Can only be placed on fields that correspond to physical columns on the table (e.g. no `@ManyToMany`/`@OneToMany`) and that are not binary (`byte[]`).
3.1.5 @DisplayImage
@DisplayImage
private byte[] image;
This annotation can be placed on binary fields to declare they are storing an image and that we want it displayed when possible. The image will be shown as a small thumbnail.
4. Security
Spring Boot Database Admin does not implement authentication and/or authorization mechanisms. However, you can use a standard Spring security configuration in order to limit access to the web UI or specific parts of it.
All Spring Boot Database Admin routes start with the value of dbadmin.baseUrl
property, and all write operations (edit, create, delete) are implemented as POST
calls.