Spring mvc plus spring data jpa how to update data gracefully

  java, question

Problems encountered

There are a lot of parameters passed from the front desk, and they correspond to model. Therefore, springmvc is automatically assigned to model by the following methods:

Java@RequestMapping(value = "xxx")
 public String xxx(Member member){
 
 bracket

After the value is assigned, since some data does not need to be updated, it is not passed in at the foreground (null in member). if it is updated directly, those null attributes will be directly set to null in the database.
I checked the information on the Internet and added comments to modle:@DynamicUpdate, can achieve the effect of dynamically updating fields that are not empty in the bean, but it is not practical. Later, I learned that I must first load the data and then update the operation of the attribute setXXX loaded.

I think of a solution

To do this with reflection, first load the object to be updated from the database, and then use reflection to read the automatically assigned object given by springmvc, and set the non-null object to load.
I wonder if there are other more elegant solutions

Can’t help but use groovy to shake a clever

public TradeHistory updateTradeHistory(int tradeId, Map<String, Object> map) {
 TradeHistory history = tradeHistoryRepository.findOne(tradeId)
 
 for (Map.Entry<String, Object> entry : map){
 history."set${entry.getKey()}"(entry.value)
 bracket
 return tradeHistoryRepository.saveAndFlush(history)
 
 bracket