[英]Adding Dynamic attribute on Spring Boot application
I have one spring boot application where I am fetching the data from my database table its one way not updating, for that I created one Entity class. 我有一个spring boot应用程序,在其中我以一种不更新的方式从数据库表中获取数据,因为我创建了一个Entity类。
Now case if like that, where I wanted to added few more attributes into existing Entity[It is the JSON at the end], finally I am pushing the update JSON entity into destination system. 现在,如果这样的话,我想在现有实体中添加更多的属性[最后是JSON],最后我将更新JSON实体推送到目标系统中。
I just wanted to add more extra attributes which destination host wanted, and it is not coming from source table. 我只是想添加目标主机想要的更多额外属性,它不是来自源表。
If you mean additional column in Entity class that you don't want to save into database, use @Transient. 如果您是指不想保存到数据库中的实体类中的其他列,请使用@Transient。
@Transient
private String destination;
You can set the values but will only be transient and will not be from database. 您可以设置值,但只能是瞬时值,而不能来自数据库。
If you want to add/merge another json check this . 如果要添加/合并另一个json, 请检查this 。
May be could be usefull for you add a new transient attribute on your entity that contains the json attributes (a custom object or the json value as String) Then create a new field on database to store the value. 可能对您有用,因为您可以在包含json属性(自定义对象或json值作为String)的实体上添加新的瞬态属性,然后在数据库上创建一个新字段来存储该值。
If this attribute is a String it's all done but if not, if were a custom object, you should use the jpa annotations below to do the conversion object/json and json/object when create/update on database and load from database: 如果此属性是String,则全部完成,如果不是,则为自定义对象,在数据库上创建/更新并从数据库加载时,应使用下面的jpa批注执行转换对象/ json和json / object:
@PrePersist, @PreUpdate, @PostLoad
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.