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);
}