简体   繁体   English

在Spring Boot应用程序上添加Dynamic属性

[英]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.

相关问题 将SSL添加到Spring Boot应用程序 - Adding SSL to Spring Boot application 在Spring Boot应用程序中添加条件外部PropertySource - Adding a conditional external PropertySource in a spring boot application 添加 SourceRoot 会导致 Spring Boot 应用程序出错 - Adding SourceRoot causes errors in spring boot application Heroku 错误:在 spring 引导应用程序的 JAR 文件中没有主清单属性 - Heroku Error: no main manifest attribute, in the JAR file for spring boot application Spring Boot 应用程序运行失败:如何修复 AnnotationConfigurationException(不存在的属性) - Spring Boot Application run failed : how to fix an AnnotationConfigurationException (nonexistent attribute) 如何在 Eclipse 中将 Spring Boot 应用程序转换为动态 Web 项目? - How to convert spring boot application to a Dynamic web project in Eclipse? static spring-boot-web 应用上的内容可以动态(刷新)吗? - Can static content on spring-boot-web application be dynamic (refreshed)? 从 Spring Boot 中的 application.properties 加载动态对象 - Load dynamic objects from application.properties in Spring Boot 添加 ssl 证书 spring 启动应用程序无法启动后 - After adding ssl certificate spring boot application fails to start 使用 postman 在 spring 引导应用程序中添加任意数量的整数 - Adding any number of integers in spring boot application using postman
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM