I am trying to create a custom ID for my Java Spring Boot project with format something like this BDI-100
. I know how to setup the number part but have no idea how to put a prefix on it. I have tried a solution from this thread in stackoverflow but it seems like it can not match with my project because of some different versions with mine.
Here is the spec of my project:
- built with Spring Tool Suite 4.18.0.RELEASE
- Java 17
- Spring Boot v3.1.3
- Built on top of ubuntu 22.04
and this is my model class. Perhaps can give the clue. Thank you for any hand guys!
package com.recruittest.bosnet.model;
import java.util.Date;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
@Entity
@Table(name = "bosnet_people")
public class People {
@Id
@Column(name = "people_id")
@SequenceGenerator(name = "PeopleIdGenerator", initialValue = 100)
@GeneratedValue(generator = "PeopleIdGenerator", strategy = GenerationType.IDENTITY)
private String id;
@Column(name = "full_name")
private String fullName;
@Column(name = "birthday")
@JsonFormat(pattern = "yyyy-mm-dd")
private Date birthday;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Override
public String toString() {
return "People [id=" + id + ", fullName=" + fullName + ", birthday=" + birthday + "]";
}
}