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

1、原生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);


2、hibernate
参数为对象
@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);

 

参考地址:
https://www.cnblogs.com/newRyan/p/12803401.html
https://zhuanlan.zhihu.com/p/104323164

posted @ 2025-03-04 16:50  郭慕荣  阅读(173)  评论(0)    收藏  举报