2016-07-27 2 views
1

다음과 같이 I는 MySQL 데이터 테이블 이슈가 있다고 가정하자 : 상기 쿼리querydsl에서 mysql now() 함수를 사용하는 방법은 무엇입니까?

artifact_id의 VARCHAR (50)
locked_status 숯 (1)
valid_till 날짜 시간

Select artifact_id from artifact where locked_status='Y' 

, 나는 다음과 같이 querydsl 표현을 가지고있다 :

SQLTemplates templates = new MySQLTemplates(); 
Configuration configuration = new Configuration(templates); 
QArtifact artifact = new QArtifact("a"); 
SQLQuery<?> query = new SQLQuery<Void>(con, templates); 
List<String> artifactIds = query.select(artifact.artifact_id) 
      .from(artifact) 
      .where(artifact.locked_status.eq("Y")) 
      .fetch(); 

querydsl에서 아래 쿼리를 어떻게 표현할 수 있습니까?

Select artifact_id from artifact where locked_status='Y' and valid_till > now() 

답변

0

가장 간단한 방법은

.and(artifact.valid_till.after(new Date())) 

을 추가하는 것입니다하지만 당신은 NOW 기능에 대한 까다로운 경우에 당신이 갈 수있는 서버에 호출 할 :

.and(artifact.valid_till.after(Expressions.currentTimestamp())) 

당신은 할 수 있습니다 이 도우미가 반환 한 DateTimeExpression이 어떻게 생성되는지 보려면 코드를 검색하십시오.

+0

이 오류 발생 - Expressions.currentTimestamp() 옵션을 사용할 때 유형 TemporalExpression 의 after (Timestamp) 메소드는 인수 (DateTimeExpression )에 적용 할 수 없습니다. – Vedha

+0

좋습니다. 다음을 시도하십시오 :'DateTimeExpression.currentTimestamp (Timestamp.class)'. 실제로 매개 변수로 다른 클래스가있는 두포의 위 표현과 같습니다. – Simon

+0

예상대로 작동했습니다. – Vedha

관련 문제