JPA查询原生语句、API两种方式查询
1.第一种方式即为代码方式查询比如下面链接这样:
https://www.cnblogs.com/zuiniub/p/14568975.html
2、3种方式见下方代码:
package com.css.oa.exam.certificate.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Repository public interface ICertificateRepository extends JpaRepository<Certificate, String>, JpaSpecificationExecutor<Certificate> { //批量删除 @Modifying @Transactional
//2.原生方式 @Query(nativeQuery = true, value = "delete from OP_CERTIFI where UUID in :ids") void deleteByIds(@Param("ids") List<String> ids);
//3.API方式,操作的是对象 @Modifying @Transactional @Query("select cer from Certificate cer where cer.student_id = :student_id") List<Certificate> myCerti(String student_id); }