JPA 多对多关联 中间表带有属性 两个外键作为中间表的联合主键时 直接操作中间表查询修改的方法
public class WorkDateTimeProductKey implements Serializable{
private static final long serialVersionUID = 3586335994284551414L;
private Product product;
private WorkDateTime workDateTime;
}public interface WorkDateTimeProductRepository extends JpaRepository<WorkDateTimeProduct, Long> {
WorkDateTimeProduct findByWorkDateTime_IdAndProduct_Id(long workDateTimeId ,long productId);
}@SpringBootTest
@RunWith(SpringRunner.class)
public class WorkDateTimeProductRepositoryTest {
@Autowired
WorkDateTimeProductRepository WorkDateTimeProductRepository;
@Test
public void findByWorkDateTimeIdAndProductIdTest(){
WorkDateTimeProduct workDateTimeProduct =WorkDateTimeProductRepository.findByWorkDateTime_IdAndProduct_Id(12l, 13l);
workDateTimeProduct.getAmount();
System.out.println(workDateTimeProduct.getAmount());
}
}Last updated