JPA 下使用原生sql,参数传递及使用方式以及JPQL参数传递使用方式

2022/3/1 19:25:35

本文主要是介绍JPA 下使用原生sql,参数传递及使用方式以及JPQL参数传递使用方式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

原生sql

参数为对象

@Query(value = "select * from user_info where username = :#{#user. username} , nativeQuery= true)
User findByUsername(User user);

参数为变量,使用?获取

@Query(value = "select * from user_info where username = ?1 , nativeQuery = true)
User findByUsername(String username);

参数为变量,使用形参名访问

@Query(value = "select * from user_info where username = :username , nativeQuery = true)
User findByUsername(String username);

JPQL

参数为对象

@Query(value = "select u from user_info u where u.username = :#{#user.username} , nativeQuery = true)
User findByUsername(User user);

参数为变量,使用?获取

@Query(value = "select u from user_info u where u.username = ?1, nativeQuery = true)
User findByUsername(String username);

参数为变量,使用形参名访问

@Query(value = "select u from user_info u where u.username = :username , nativeQuery = true)
User findByUsername(String username);


这篇关于JPA 下使用原生sql,参数传递及使用方式以及JPQL参数传递使用方式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程