Appearance
Display Format Guessing
When no explicit displayFormat is provided on an entity, Squizy automatically generates a reasonable display format based on the entity's ID structure.
How It Works
The DisplayFormatFactory follows this logic:
- If a
@DisplayFormatannotation is present (on the class or via@SquizyEntity(displayFormat = ...)), use it as-is - Otherwise, generate a best-effort format based on the entity's ID fields
Best-Effort Rules
- Single simple ID: The display format is
${idFieldName} - Composite ID (multiple
@Idfields): Fields are joined with-separator, e.g.,${field1} - ${field2} - Embedded ID (
@EmbeddedId): The embedded ID's component fields are used, prefixed with the ID field name, e.g.,${id.author} - ${id.title}
Examples
java
// Generated format: ${id}
@Entity
@SquizyEntity
public class SimpleEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}java
// Explicit format: ${name}
@Entity
@SquizyEntity
@DisplayFormat("${name}")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
}java
// Generated format: ${id.isbn} - ${id.author}
@Entity
@SquizyEntity
public class Book {
@EmbeddedId
private BookId id;
}
@Embeddable
public class BookId {
private String isbn;
private String author;
}Field-Level Display Format
When an entity field references another entity, you can override how that referenced entity is displayed for that specific field using @DisplayFormat on fields or @SquizyField(displayFormat = ...):
java
@Entity
@SquizyEntity
public class Address {
// Show city as "id - name" instead of the City entity's default display format
@SquizyField(displayFormat = "${id} - ${name}")
@ManyToOne
private City city;
}If no field-level override is present, the referenced entity's own displayFormat is used.
Embedded Fields
For embedded (non-entity) types, the display format resolution checks:
@DisplayFormaton the field@DisplayFormaton the embedded class- Falls back to empty (no specific display format)