Beanutils.copyProperties (Ignore more than one field)

Asked

Viewed 245 times

0

all right? I am using java and spring-framework in a restful project, so I created the following class:

Categoria 

    (id, descrição, dtCadastro, dtAlteração)

In class I am using the annotations @PrePersist and @PreUpdate for date fields, so they are automatically updated when I persist with a new object or when I update an existing object.

In the application I manipulate objects of this type using a DTO (Categoriadto) with the following attributes:

(id, descrição)

The date fields were omitted because they are fields used for auditing the persisted data and are not manipulated by the client.

The problem is that when I use Beanutils.copyProperties in an update end point it ends up generating null in the date fields, because DTO does not have these fields.

Beanutils.copyProperties also has a signature that lets you ignore a field, I’m using it to ignore the id in the update process.

 BeanUtils.copyProperties(dto, dtoAtualizado, "id");

Is there any class that has a similar method (copy values from fields to another object) but that allows ignoring more than one field?

Thanks for the returns.

1 answer

0


Actually there was a mistaken use on my part. The method copy.Pproperties() can ignore more than one field. For this, just keep inserting the fields separated by comma, IE, the class meets the need of the application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.