gpt4 book ai didi

mysql - 如何获取收藏

转载 作者:行者123 更新时间:2023-11-29 19:18:15 40 4
gpt4 key购买 nike

我在 QueryDsl 中编写一个查询时遇到问题。我是用sql写的。其外观如下:

select * from isa_proj.restaurant_table where isa_proj.restaurant_table.id not in 
(SELECT restaurant_table_id FROM isa_proj.reservation r where r.restaurant_id = 1 AND
reservation_begin not between CAST('2017-02-17 7:30' AS datetime) and CAST('2017-02-17 9:30' AS datetime) and
reservation_expire not between CAST('2017-02-17 7:30' AS datetime) and CAST('2017-02-17 9:30' AS datetime));

我尝试过这个:

Predicate pred = QRestaurantTable.restaurantTable.id.eq(id).notIn(QReservation.reservation.restaurant.id.eq(id).and(
QReservation.reservation.reservationBegin.notBetween(start, end)).and(
QReservation.reservation.reservationEnd.notBetween(start, end)));

但我收到此错误消息:

The method notIn(Number...) in the type NumberExpression<Long> is not applicable for the arguments (BooleanExpression)

这是我第一次使用 QueryDsl。我不知道如何从以下位置获取restaurant_table_id:

QReservation.reservation.restaurant.id.eq(id).and(
QReservation.reservation.reservationBegin.notBetween(start, end)).and(
QReservation.reservation.reservationEnd.notBetween(start, end))

...或者如何正确地做到这一点。

编辑: pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>restaurant</groupId>
<artifactId>isa_proj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>isa_proj</name>
<url>http://maven.apache.org</url>
<description>WEB application used for study purpose.</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>



</dependencies>

<build>
<plugins>

<!-- https://github.com/querydsl/apt-maven-plugin -->
<!--Dependency: https://mvnrepository.com/artifact/com.querydsl/querydsl-apt -->
<!-- <plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>src/main/java/restaurant/jpa/domain/queries</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.4</version>
</dependency>
</dependencies>
</plugin> -->


<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

</plugins>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>

谢谢。米洛拉德·西米克

最佳答案

你可以试试这个:

Predicate pred = QRestaurantTable.restaurantTable.id.notIn(new JPASubQuery()
.from(QReservation.reservation.restaurant)
.where(QReservation.reservation.restaurant.id.eq(id)
.and(QReservation.reservation.reservationBegin.notBetween(start, end))
.and(QReservation.reservation.reservationEnd.notBetween(start, end)))
.list(QReservation.reservation.restaurantTable.id));

关于mysql - 如何获取收藏<?从 QueryDsl 中的 BooleanExpession 扩展 Long>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42589728/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com