在不使用实体的情况下,使用JpaRepository交互风格可以通过以下步骤进行解决:
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface MyRepository extends JpaRepository
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MyService {
private final MyRepository myRepository;
@Autowired
public MyService(MyRepository myRepository) {
this.myRepository = myRepository;
}
// 使用MyRepository进行数据库交互
public void doSomething() {
// ...
}
}
public void doSomething() {
List
通过以上步骤,就可以在不使用实体的情况下使用JpaRepository交互风格进行数据库操作。
下一篇:不使用实体发送Laravel通知