@Query(nativeQuery = true,value = "SELECT a.id , e.created_date as time FROM jg_bed a,jg_checkin_bed b ,jg_checkin c , jg_elder d, jg_checkout e WHERE a.id = b.bed_id and b.checkin_id = c.id and c.elder_id = d.id and d.id = e.elder_id and c.usage = ?1 and c.move_in_status =?2 and a.tenant_id = ?3 " + " <if test='queryData != null'> " + " and e.checkout_date between #{queryData.bedCheckOutStartTime} and #{queryData.bedCheckOutEndTime}" + " and a.bed_status = #{queryData.bedStatus} " + "</if>") List<Map<String,String>>getCheckOutTimeAndBedId(String usage, String moveInStatusCheckOutDoing , String tenantId, @Param("queryData") QueryData queryData);改正为jpa写法
时间: 2024-03-27 20:37:08 浏览: 66
以下是可能的JPA写法:
```java
@Query("SELECT a.id, e.createdDate as time " +
"FROM Bed a " +
"JOIN CheckinBed b ON a.id = b.bed.id " +
"JOIN Checkin c ON b.checkin.id = c.id " +
"JOIN Elder d ON c.elder.id = d.id " +
"JOIN Checkout e ON d.id = e.elder.id " +
"WHERE c.usage = ?1 " +
"AND c.moveInStatus = ?2 " +
"AND a.tenant.id = ?3 " +
"AND (:queryData is null OR " +
" (e.checkoutDate BETWEEN :#{#queryData.bedCheckOutStartTime} AND :#{#queryData.bedCheckOutEndTime} " +
" AND a.bedStatus = :#{#queryData.bedStatus}))")
List<Map<String, String>> getCheckOutTimeAndBedId(String usage, String moveInStatusCheckOutDoing, String tenantId, @Param("queryData") QueryData queryData);
```
需要注意以下几点:
- 在JPA中,需要使用实体类名、属性名等代替表名、列名等,因此需要根据实际情况对表名、列名进行替换。
- 在JPA中,使用`JOIN`关键字代替SQL中的多表查询语句。
- 在JPA中,使用`:`代替`#{}`,使用`#`代替`${}`。同时,为了避免语法错误,需要将参数名放在`#{}`或`${}`中的写法改成使用`:`和`#{#参数名}`的写法。
- 在JPA中,使用`is null`代替SQL中的`= null`判断。
- 在JPA中,使用`@Param`注解指定参数名。
阅读全文