spring data jpa 多對一聯表查詢
資料庫:
實體類:
public class Product {
@Id
@GeneratedValue
private Long id;
private String name;
private Double price;
private String standerd;
private String code;
private String srcPath;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
//其他setter,getter省略
Repository :
public interface ProductRepository extends JpaRepository<Product,Long> {
@Query("select p from Product p join p.user u where u.id=?1 ")
List<Product> findByUserId(@Param("userId") Long userId);
}
controller:
@PostMapping("/findProductByUserName")
public List<Product> findProductByName(@RequestParam("name")String name){
User user=userService.findByProperty(name);
List<Product> productList=productService.findByUserId(user.getId());
return productList;
}
前端post請求測試:
相關文章
- spring data jpa關聯查詢(一對一、一對多、多對多)Spring
- Spring Data JPA 實現聯表查詢Spring
- Spring JPA 聯表查詢Spring
- spring data jpa查詢Spring
- Spring Data JPA 實現多表關聯查詢Spring
- jpa一對多查詢
- spring-data-jpa一對多、多對多雙向關聯,查詢操作的時候進入死迴圈問題Spring
- Spring Data JPA 之 一對一,一對多,多對多 關係對映Spring
- springDataJpa聯表查詢之多對多Spring
- JPA(3) 表關聯關係(多對一、一對多、多對多、一對一)
- spring data JPA 模糊查詢 --- 使用 LIKE --- 的寫法Spring
- Spring Data Jpa 複雜查詢總結 (多表關聯 以及 自定義分頁 )Spring
- Spring Data JPA + QueryDSL實現CRUD和複雜查詢案例Spring
- JPA 連表查詢
- Spring JPA聯表情況下的複雜查詢Spring
- Spring Data Jpa 的簡單查詢多表查詢HQL,SQL ,動態查詢, QueryDsl ,自定義查詢筆記SpringSQL筆記
- JPA多表關聯查詢
- Spring Data JpaSpring
- Spring Data JPA之Spring Data JPA快速入門(三)Spring
- Spring JPA 定義查詢方法Spring
- JPA 之 多表聯合查詢
- jpa動態查詢與多表聯合查詢
- 一文搞定 Spring Data JPASpring
- Spring Data Jpa APISpringAPI
- SpringBoot Jpa多條件查詢Spring Boot
- SpringMVC+Spring Data JPA +Bootstrap 分頁實現和模糊查詢分頁SpringMVCboot
- Spring Boot:整合Spring Data JPASpring Boot
- gorm 關係一對一,一對多,多對多查詢GoORM
- Spring Data JPA 的使用Spring
- Spring Data JPA中TransactionInterceptorSpring
- Spring Data JPA中ConfigurableTransactionManagerSpring
- SpringBoot整合Spring Data JPASpring Boot
- Spring Data JPA:解析SimpleJpaRepositorySpring
- Spring Data JPA:解析CriteriaQuerySpring
- Spring Data JPA:解析CriteriaBuilderSpringUI
- MyBatis表關聯 一對多 多對一 多對多MyBatis
- [增刪改查] 最規範的 JPA 一對多/多對一 CRUD 示例
- Spring Data JPA基本增刪改查和JPQL查詢(含完整程式碼和視訊連線)Spring