2014-11-05 138 views
-2

我是jsf和java的新手,现在正在使用jpa和jpql构建带有jsf的web项目。 现在,在我的项目写JPQL查询我这样做:Querydsl jpa入门

Query q = em.createQuery("SELECT a FROM Advert as a where a.razdel like ?1 and a.categoryId like ?2" ); 

但我已阅读,查询DSL是使用更更好,无限便捷。 所以我读过一些教程,发现有这样的:

Add the following dependencies to your Maven project and make sure that the Maven 2 repo of Mysema Source (http://source.mysema.com/maven2/releases) is accessible from your POM : 



<dependency> 
    <groupId>com.mysema.querydsl</groupId> 
    <artifactId>querydsl-apt</artifactId> 
    <version>${querydsl.version}</version> 
    <scope>provided</scope> 
</dependency>  

<dependency> 
    <groupId>com.mysema.querydsl</groupId> 
    <artifactId>querydsl-jpa</artifactId> 
    <version>${querydsl.version}</version> 
</dependency> 

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>1.6.1</version> 
</dependency> 

但是,在添加此设置? 在我的项目中,我只有web.xml,persistence.xml,这就是全部?

+1

这是Maven。所以学习[Maven](http://maven.apache.org/)或找到其他教程。 – 2014-11-05 12:59:34

回答

1

你必须在这样的部分中添加该文件pom.xml在:

<dependencies> 
    // add the stuff here 
</dependencies> 

为了使这项工作,你可能有一个<property>定义${querydsl.version}值。这应该与此类似:

<properties> 
    <querydsl.version>THE_REAL_VERSION_NUMBER</querydsl.version> 
</properties> 

看起来你还必须添加这些文件可以下载库:

<repositories> 
    <repository> 
     <id>Mysema Source</id> 
     <name>Mysema Source - Releases</name> 
     <url>http://source.mysema.com/maven2/releases)</url> 
    </repository> 
</repositories> 

如果没有pom.xml,你不”没有基于Maven的项目。如果是这种情况,你应该阅读一个基本的Maven教程。

如果您不想使用Maven,您也可以手动下载所需的库jar文件,并将它们放入Web应用程序的WEB-INF/lib文件夹中。