(1)數據庫更新時間和測試的技巧

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);
    }	
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章