一、Spring Data Jpa
因为我们使用共通类BeanUtils,BeanUtils默认把ID主键值设置数值,通过Jpa插入数据库时如果主键在数据库中存在Jpa会默认做update操作。所以导致数据丢失。
import org.apache.commons.beanutils.BeanUtils;
BeanUtils.copyProperties(aftBean,befBean);pom依赖
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.2</version>
        </dependency>解决方案:
重新对id主键设置默认值0/null,数据库中不存在的主键值。
使用Jpa savaAndFlush()方法更新。










