计算插入时受影响的行

时间:2019-01-03 02:38:23

标签: java spring-boot crud rows-affected

我正在尝试在插入时获取受影响的行。我已经看到了一些解决方案,但是我不知道如何在我的代码中应用它。我正在使用Spring Boot,但尚未掌握它。这是我的示例代码:

型号:

@Entity
@Table(name="test_table")
public class TestTable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "name")
    private String name;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

存储库:

public interface TestTableRepository extends CrudRepository<TestTable, Long> {

}

服务:

public interface TestTableService {
    public void saveOrUpdate(TestTable testTable);
}

服务Impl:

@Override
public void saveOrUpdate(TestTable testTable) {
    testTableRepository.save(testTable);
}

有一些唯一的行,所以我需要知道它是否插入。

希望您能帮助我。谢谢

0 个答案:

没有答案