'Accessing header attributes from model in java spring boot
I'd like to access the value of "accept-language" in header from model so i can determine which column should i pick.
so for now i have this in my model
@Entity
@Table(name = "categories")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "title_en")
private String title;
@Column(name = "description_en")
private String description;
private String icon;
}
so i need to change the name of column according to the header language i received , for example if i received (fr) i want to receive the value of column name_fr
@Column(name = "title_fr")
Any help is appreciated. Thanks
Solution 1:[1]
I would consider your DB design
I would have a CategoriesInLanguage table with three columns
@Entity
@Table(name = "CategoriesInLanguage")
public class CategoryInLanguage {
private Integer idCategory;
@Column(name = "title")
private String title;
@Column(name = "description")
private String description;
@Column(name = language")
private String = language
}
@Entity
@Table(name = "categories")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToMany
@JoinColumn(name="idCategory")
public List<CategoryInLanguage> getLanguages() {
return languages;
}
}
something like this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
