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


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

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);

更多JPQL操作1
更多JPQL操作2


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM