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 @   郭慕荣  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2022-03-04 Git 对已经加入版本控制的文件,修改后希望不被提交办法
点击右上角即可分享
微信分享提示