1.@DynamicUpdate 修改本条记录更新数据库时间
2.@Entity 对应数据库表字段
3.@Data 省去GetSet方法
@Entity
@DynamicUpdate
@Data
public class ProductCategory {
/** 类目id. */
@Id
@GeneratedValue
private Integer categoryId;
/** 类目名字. */
private String categoryName;
/** 类目编号. */
private Integer categoryType;
测试@Test方法里面使用
@Transactional 可以回滚数据库里面的测试记录,在spring 里面是事务方法
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProductCategoryRepositoryTest {
@Autowired
private ProductCategoryRepository repository;
@Test
@Transactional
public void saveTest() {
ProductCategory productCategory = new ProductCategory("最爱", 4);
ProductCategory result = repository.save(productCategory);
Assert.assertNotNull(result);
}