目的:想获取中间表的值。
方式
1、联合主键。
public class PersonAndLanguageId implements Serializable {
private Long languageId;
private Long personId;
}
2、实体类
@Entity
@Data
@IdClass(PersonAndLanguageId.class)
public class PersonLanguage implements Serializable {
@Id
@Column(name = "person_id")
private Long personId;
@Id
@Column(name = "language_id")
private Long languageId;
@Column(name = "name")
private String name;
}
3、仓库
@Repository
public interface PersonLanguageDao extends JpaRepository<PersonLanguage, PersonAndLanguageId> {
}
4、请求
http://localhost:8001/jpa/personLanguages/?sort=id,desc&page=0&size=3
5、结果
请问
为什么获取不到联合主键的值,怎么才能获取联合主键的值?