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
Since Spring Boot Database Admin is distributed on Maven, the easiest way to start is to include this dependency in your pom.xml
:
<dependency>
<groupId>tech.ailef</groupId>
<artifactId>spring-boot-db-admin</artifactId>
<version>0.1.2</version>
</dependency>
TIP Go to the Maven repository to retrieve the exact snippet for the latest stable release.
If you want the latest unstable release, you can clone the main
branch of the Github repo and execute mvn install -D skipTests
in the project's directory. This will install the library in your local repository, which you can then include using the same snippet as above, but replacing the version number with the one contained in the pom.xml
file of the code you pulled from Github.
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
Supported parameters
Name | Type | Required | Description |
---|---|---|---|
name | String | false | The name of this column in the web interface. The method's name is used if this value is not specified. |
Code example
@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
Supported parameters
Name | Required | Type | Description |
---|---|---|---|
type | false | Enum (DEFAULT , CATEGORICAL ) |
If CATEGORICAL , this changes the filter in the UI to shows all the possible values directly instead of providing a autocomplete form. |
Code example
@Filterable
private LocalDate createdAt;
@Filterable(type=FilterableType.CATEGORICAL)
@ManyToOne
private User user;
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.