Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use spring data jpa custom sql mode

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Jpa two ways to customize SQL

When your abstract class inherits the JpaRepository class, you will have some basic add, delete, change and search operations. However, in many cases, these simple features are not enough, and jpa also supports custom queries for native SQL and entity class SQL.

1. Native SQL@Query (value = "SELECT t2.userId, t1.title, t1.content, t1.completeTime, t2.scheduleState" + "FROM schedule T1 LEFT JOIN schedule_user T2 ON t1.id = t2.schedule_id" + "WHERE t2.user_id =? 1 AND t2.schedule_state =? 2", nativeQuery=true) List findScheduleListByState (Long userId, int scheduleState); 2. Entity class SQL@Query (value = "SELECT new com.x3.schedule.saas.table.ScheduleUserView (" + "t2.userId, t1.title, t1.content, t1.completeTime, t2.scheduleState)" + "FROM ScheduleTable T1 LEFT JOIN ScheduleUserTable T2 ON t1.scheduleId = t2.scheduleId" + "WHERE t2.userId =? 1 AND t2.scheduleState =? 2") List findScheduleListByState (Long userId, int scheduleState) This is the end of the content of "how to use spring data jpa Custom sql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report