SpringBoot-JPAのカスタムSQL(ページング)声明

package com.example.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.example.bean.Product;

public interface ProductDao extends JpaRepository<Product, Integer>{
	
	@Query(value = "select * from product p where p.cid=?1", nativeQuery=true)
	public Page<Product> findByCategory_id(int cid, Pageable pageable);
	

}

注意了:
	即使是用@Query自定义SQL语句, 其中方法的命名也是讲究的, 否则会报黄色警告的!

findByCategory_id中:
1、Category是外键类
2、_id是外键类的属性

只涉及查询的SQL语句只用 @Query 就好了
如果涉及到更新,删除,插入的话就要加 @Modifying 了

質問:

私は唯一の「nativeQuery = true」を使用することができますなぜ私はエラーそして、そうでない場合、私はHQLを書きます、わかりません

公開された63元の記事 ウォンの賞賛1 ビュー2661

おすすめ

転載: blog.csdn.net/qq_42039738/article/details/104613056